In the implementation of linux kernel lists in /include/linux/list.h
, what is the rationale behind the first line (pasted below) of the container_of
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.