[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200808181109.43203.rusty@rustcorp.com.au>
Date: Mon, 18 Aug 2008 11:09:42 +1000
From: Rusty Russell <rusty@...tcorp.com.au>
To: Ingo Molnar <mingo@...e.hu>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Sam Ravnborg <sam@...nborg.org>
Subject: Re: [PATCH] debug: fix BUILD_BUG_ON() for non-constant expressions
On Monday 18 August 2008 03:33:19 Ingo Molnar wrote:
> * Linus Torvalds <torvalds@...ux-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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists