[1/2] Make BUILD_BUG_ON fail at compile time.

From: Andi Kleen
Date: Sat Sep 10 2005 - 07:05:09 EST


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@xxxxxxxxxx

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;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/