2005-09-10 12:04:42

by Andi Kleen

[permalink] [raw]
Subject: [1/2] Make BUILD_BUG_ON fail at compile time.

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: [email protected]

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;


2005-09-10 13:22:09

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [1/2] Make BUILD_BUG_ON fail at compile time.

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: [email protected]

reiser4 seems to have a duplicate version of this, Hans, can you switch
over to the common one once this is in?

2005-09-12 18:02:04

by Hans Reiser

[permalink] [raw]
Subject: Re: [1/2] Make BUILD_BUG_ON fail at compile time.

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: [email protected]
>>
>>
>
>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.