Я читаю разработку драйверов устройств Linux от Джона Мэдиу, и один из них говорит:
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.
Это определение container_of
:
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr);
(type *)( (char *)__mptr - offsetof(type,member) );})
Так что, если у меня есть
struct person {
int age;
int salary;
char *name;
} me;
а у меня char ** my_name = &(me.name);
, почему я не могу сделать следующее:
struct person * me = container_of(my_name,struct person,name);