public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Andi Kleen" <ak@suse.de>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, jbeulich@novell.com
Subject: [1/2] Make BUILD_BUG_ON fail at compile time.
Date: Sat, 10 Sep 2005 14:04:40 +0200	[thread overview]
Message-ID: <4322CBD8.mailE1M1FX8RR@suse.de> (raw)

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;

             reply	other threads:[~2005-09-10 12:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-10 12:04 Andi Kleen [this message]
2005-09-10 13:22 ` [1/2] Make BUILD_BUG_ON fail at compile time Christoph Hellwig
2005-09-12 18:01   ` Hans Reiser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4322CBD8.mailE1M1FX8RR@suse.de \
    --to=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=jbeulich@novell.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox