public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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