blackjack
Newbie level 3
A few days ago, I was looking for some macro that satisfy the demand: calculating the location of a struture with the address and the name of some field and as parameters. Finally, I've found the following:
// ptr : the address of the field
// member : the name of the field
// type : the type of the structure
#define get_container(ptr, type, member) \
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
And it works, but I don't know how it does. Could somebody explain it for me, please?
*See attached file for example code.
// ptr : the address of the field
// member : the name of the field
// type : the type of the structure
#define get_container(ptr, type, member) \
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
And it works, but I don't know how it does. Could somebody explain it for me, please?
*See attached file for example code.