Rationale behind the container_of macro in linux/list.h

It adds some type checking. With your version, this compiles fine (without warning):

struct foo { int bar; };

....

float a;
struct foo *var = container_of(&a, foo, bar);

With the kernel version, the compiler reports:

warning: initialization from incompatible pointer type

Good explanation of how the macro works: container_of by Greg Kroah-Hartman.

Leave a Comment