[ccan] container_of_var() macro broken for compilers without typeof()

Delio Brignoli brignoli.delio at gmail.com
Wed Nov 10 08:43:21 EST 2010


Hello Rusty,

Thanks for setting up ccan. The code I am developing is using list.h and has to compile on windows with Visual C and GCC on linux, but the container_of_var() macro will not work for compilers that #define HAVE_TYPEOF 0, because (a) the #ifdef is always true (maybe this is deliberate) and (b) 'containing_type' is undefined. I understand this cannot be fixed (*) but I was wondering if the #else branch should contain and #error to display an explicit error message.

(*) except by changing the list's interface, which I suspect would not be a popular solution.

Cheers
--
Delio

The offending bit of container_of.h for reference:

#ifdef HAVE_TYPEOF
#define container_of_var(member_ptr, var, member) \
	container_of(member_ptr, typeof(*var), member)
#else
#define container_of_var(member_ptr, var, member) \
	((void *)((char *)(member_ptr) - offsetof(containing_type, member)))
#endif
#endif



More information about the ccan mailing list