hi,
can any one explain me what this little macro is doing?
-
#define pos_of(h, f) ((short int) &((h *) 0)->f)
-
h is a struct
f is a member of it
i have no clue, i only know it has something to do with the position.
Suppose you have a struct of type 'h' somewhere in memory, say starting at
address 'a'. Then the member 'f' is located somewhere in memory at location,
say 'a+x'. That macro finds that number 'x'.
If you have a pointer to such a struct 's' you could've done this:
-
short int pos_of= ((char*)&(s->f))-((char*)&s);
-
This macro doesn't assume that you have an actual struct in memory somewhere,
so it supposes that you have a struct at location 0 (there is none, but as long
as you don't dereference that address all is fine).
So if that imaginary struct is located at 0 (((char*)&s) == 0), then the position
of f of that imaginary struct is at position ((short int)&((h*)0)->f))
(I'm sure I goofed with the parentheses here ;-)
kind regards,
Jos