* [1/2] Make BUILD_BUG_ON fail at compile time.
@ 2005-09-10 12:04 Andi Kleen
2005-09-10 13:22 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2005-09-10 12:04 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, jbeulich
Make BUILD_BUG_ON fail at compile time.
Force a compiler error instead of a link error, because they
are easier to track down. Idea stolen from code by Jan Beulich.
Cc: jbeulich@novell.com
Index: linux/include/linux/kernel.h
===================================================================
--- linux.orig/include/linux/kernel.h
+++ linux/include/linux/kernel.h
@@ -307,8 +307,8 @@ struct sysinfo {
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
-extern void BUILD_BUG(void);
-#define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
+/* Force a compilation error if condition is false */
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#ifdef CONFIG_SYSCTL
extern int randomize_va_space;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [1/2] Make BUILD_BUG_ON fail at compile time.
2005-09-10 12:04 [1/2] Make BUILD_BUG_ON fail at compile time Andi Kleen
@ 2005-09-10 13:22 ` Christoph Hellwig
2005-09-12 18:01 ` Hans Reiser
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2005-09-10 13:22 UTC (permalink / raw)
To: Andi Kleen; +Cc: akpm, linux-kernel, jbeulich, reiser
On Sat, Sep 10, 2005 at 02:04:40PM +0200, Andi Kleen wrote:
> Make BUILD_BUG_ON fail at compile time.
>
> Force a compiler error instead of a link error, because they
> are easier to track down. Idea stolen from code by Jan Beulich.
>
> Cc: jbeulich@novell.com
reiser4 seems to have a duplicate version of this, Hans, can you switch
over to the common one once this is in?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [1/2] Make BUILD_BUG_ON fail at compile time.
2005-09-10 13:22 ` Christoph Hellwig
@ 2005-09-12 18:01 ` Hans Reiser
0 siblings, 0 replies; 3+ messages in thread
From: Hans Reiser @ 2005-09-12 18:01 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andi Kleen, akpm, linux-kernel, jbeulich
Christoph Hellwig wrote:
>On Sat, Sep 10, 2005 at 02:04:40PM +0200, Andi Kleen wrote:
>
>
>>Make BUILD_BUG_ON fail at compile time.
>>
>>Force a compiler error instead of a link error, because they
>>are easier to track down. Idea stolen from code by Jan Beulich.
>>
>>Cc: jbeulich@novell.com
>>
>>
>
>reiser4 seems to have a duplicate version of this, Hans, can you switch
>over to the common one once this is in?
>
>
>
>
>
Yes we can.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-12 18:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-10 12:04 [1/2] Make BUILD_BUG_ON fail at compile time Andi Kleen
2005-09-10 13:22 ` Christoph Hellwig
2005-09-12 18:01 ` Hans Reiser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox