lkml.org 
[lkml]   [2008]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] debug: fix BUILD_BUG_ON() for non-constant expressions
Date
On Monday 18 August 2008 03:33:19 Ingo Molnar wrote:
> * Linus Torvalds <torvalds@linux-foundation.org> wrote:
> > Gag me now.
> >
> > Why not just do
> >
> > #define __BBO(c) sizeof(const char[1 - 2*!!(c)])
> > #define __BBONC(c) __BBO(!__builtin_constant_p(c))
> > #define BUILD_BUG_ON_ZERO(c) (__BBO(c) - __BBONC(c))
> > #define BUILD_BUG_ON(c) (void)BUILD_BUG_ON_ZERO(c)
> >
> > and be done with it?
>
> yeah, i first tried a few variants of that (compile-time warnings are
> much better than link time warnings), but none worked when i tested
> various failure modes.

Hey, I thought I was the "undisputed ruler of Ugly-land".

How about this instead:

#define BUILD_BUG_ON(condition) \
do { \
static struct { char arr[1 - 2*!!(condition)]; } x __maybe_unused; \
} while(0)

Cheers,
Rusty.


\
 
 \ /
  Last update: 2008-08-18 06:01    [W:0.072 / U:4.892 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site