Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()

From: Peter Zijlstra
Date: Tue May 23 2017 - 07:24:36 EST


On Tue, May 23, 2017 at 11:32:02AM +0100, Ian Abbott wrote:

> > #define container_of(ptr, type, member) ( \
> > _Static_assert(__builtin_types_compatible_p( \
> > typeof(*ptr), typeof( ((type *)0)->member )), "WUT"), \
> > ((type *)((char *)(ptr) - offsetof(type, member))); \
> > )
>
> It's a fine suggestion (if more parentheses are added), but _Static_assert
> is a C11 feature, and I thought the kernel was using gnu89 (unless it's been
> updated since).

We have BUILD_BUG_ON() that should be similar in functionality.