I am reading Linux Device Drivers Development from John Madieu and one para says
The container_of macro won't work for char * or array members. It
means the first member of container_of must not be a pointer to
another pointer to char nor to array in the structure.
This is the definition of container_of
:
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr);
(type *)( (char *)__mptr - offsetof(type,member) );})
So if I have
struct person {
int age;
int salary;
char *name;
} me;
and I have char ** my_name = &(me.name);
, why can't I do the following :
struct person * me = container_of(my_name,struct person,name);