Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1647950

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

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of()
Date 2017-05-23 13:30 +0200
Message-ID <tKgaK-2wv-15@gated-at.bofh.it> (permalink)
References <tJXhM-7lx-7@gated-at.bofh.it> <tJZMC-gQ-13@gated-at.bofh.it> <tKfol-1W6-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] kernel.h: handle pointers to arrays better in container_of() Ian Abbott <abbotti@mev.co.uk> - 2017-05-22 17:20 +0200
  Re: [PATCH v2] kernel.h: handle pointers to arrays better in container_of() Michal Nazarewicz <mina86@mina86.com> - 2017-05-22 20:00 +0200
    Re: [PATCH v2] kernel.h: handle pointers to arrays better in  container_of() Ian Abbott <abbotti@mev.co.uk> - 2017-05-23 12:40 +0200
      Re: [PATCH v2] kernel.h: handle pointers to arrays better in  container_of() Peter Zijlstra <peterz@infradead.org> - 2017-05-23 13:30 +0200
        Re: [PATCH v2] kernel.h: handle pointers to arrays better in  container_of() Ian Abbott <abbotti@mev.co.uk> - 2017-05-23 14:10 +0200
          Re: [PATCH v2] kernel.h: handle pointers to arrays better in  container_of() Ian Abbott <abbotti@mev.co.uk> - 2017-05-23 15:40 +0200
            Re: [PATCH v2] kernel.h: handle pointers to arrays better in  container_of() Ian Abbott <abbotti@mev.co.uk> - 2017-05-23 16:20 +0200

csiph-web