[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <48BC1065.76E4.0078.0@novell.com>
Date: Mon, 01 Sep 2008 14:55:17 +0100
From: "Jan Beulich" <jbeulich@...ell.com>
To: "Boaz Harrosh" <bharrosh@...asas.com>,
"Rusty Russell" <rusty@...tcorp.com.au>
Cc: "David S. Miller" <davem@...emloft.net>,
"Ingo Molnar" <mingo@...e.hu>,
"Alexey Dobriyan" <adobriyan@...il.com>,
"Ivo van Doorn" <IvDoorn@...il.com>,
"Andrew Morton" <akpm@...ux-foundation.org>,
"Linus Torvalds" <torvalds@...ux-foundation.org>,
"Theodore Tso" <tytso@....edu>,
"John W. Linville" <linville@...driver.com>,
"linux-kernel" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 5/5] debug: BUILD_BUG_ON: error on non-const
expressions
>>> Boaz Harrosh <bharrosh@...asas.com> 01.09.08 15:28 >>>
>--- a/include/linux/compiler.h
>+++ b/include/linux/compiler.h
>@@ -195,7 +195,10 @@ extern void __chk_io_ptr(const volatile void __iomem *);
> #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
>
> /* Force a compilation error if condition is true */
>-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
>+#define BUILD_BUG_ON(condition) \
>+do { \
>+ static struct { char arr[1 - 2*!!(condition)]; } x __maybe_unused;\
>+} while(0)
>
> /* Force a compilation error if condition is true, but also produce a
> result (of value 0 and type size_t), so the expression can be used
I have to admit that I'm surprise this compiles: You replace an expression
with a statement, and hence you reduce the places where BUILD_BUG_ON()
can validly be used. Of course you could wrap the whole thing in ({}),
but I can't see why not to use a bit-field to achieve the intended effect.
Also, are you sure the compiler will eliminate the dead variable in all
cases?
Finally, using as common a variable as 'x' here seems dangerous, too:
What if somewhere x is #define-d to something more complex than a
simple identifier?
Jan
--
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