Re: What u mean by this statemnet ?.



Umesh wrote:
what this statement &(*IR)->func means.

where IR is the pointer to structure & func is pointer to fuction.
func is the member of structure.

a->b is the same as (*a).b. Thus, IR cannot be a pointer to struct but is a pointer to a pointer to struct, as it is dereferenced twice: (*IR)->func means (**IR).func Now, you apply the address operator. This gives you the address where the function pointer (**IR).func is stored.

Observe:

#include <stdio.h>

int main (void)
{
  struct test {
    int filler;
    void (*func)(void);
  } instance, *pinst, **IR;
  int offset = offsetof(struct test, func);

  instance.filler = 0;
  instance.func   = NULL;
  pinst = &instance;
  IR = &pinst;

  printf("inst: %p func: %p %p\n", (void *)(&instance),
         (void *)(&instance.func), (void *)(&(*IR)->func));
  printf("distance: %d %d\n", (int) offset,
         (int) ((unsigned char*)(&(*IR)->func)-(unsigned char*)(*IR)));

  return 0;
}


Cheers Michael -- E-Mail: Mine is an /at/ gmx /dot/ de address. .



Relevant Pages

  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: Another spinoza challenge
    ... int main{ ... using struct and typedef. ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: [RFC][PATCH 1/6] memcg: fix pre_destory handler
    ... returns struct cgroup of id. ... SwapCgroup uses array of "pointer" to record the owner of swaps. ... struct cgroup_id is freed by RCU. ... changed interface from pointer to "int" ...
    (Linux-Kernel)
  • gcc, aliasing rules and unions
    ... struct B {int x, y;}; ... A struct pointer can be converted to another ... Also I don't know what the "effective type" of a union member is. ...
    (comp.lang.c)