Reputation: 35
If I have:
struct my_container {
int x;
struct some_struct *ss;
}
If I have the pointer ss through which I can access the members inside some_struct, I should be able to access my_container by doing the following right ? This is what I am doing:
struct my_container *my_c;
my_c = container_of(&ss, struct my_container, ss)
But this is not working for sure and I am not able to comprehend why. Can someone help me with this? Is there something that I am missing ?
Upvotes: 3
Views: 5633
Reputation: 11706
If you only have a pointer to some_struct
(i.e. if you just have struct some_struct *ss;
), you cannot use the container_of
macro in this way, as &ss
will just evaluate to the address of some variable, not the address of my_container
. To use it properly, you'll need a pointer to a pointer to some_struct
(i.e. struct some_struct **pss
).
Upvotes: 4