utils: add BUILD_BUG_ON (similar to the one in the linux kernel)
authorFelix Fietkau <nbd@openwrt.org>
Tue, 1 Jan 2013 15:10:27 +0000 (16:10 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 1 Jan 2013 15:10:44 +0000 (16:10 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
utils.h

diff --git a/utils.h b/utils.h
index d1a6cd33699eecb1eff61c798013fb7d198463f2..a86894aa57b1ec25935771dbe828c5a11837a264 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -38,4 +38,18 @@ void *__calloc_a(size_t len, ...);
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
+#define __BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+
+#ifdef __OPTIMIZE__
+extern int __BUILD_BUG_ON_CONDITION_FAILED;
+#define BUILD_BUG_ON(condition)                                        \
+       do {                                                    \
+               __BUILD_BUG_ON(condition);                      \
+               if (condition)                                  \
+                       __BUILD_BUG_ON_CONDITION_FAILED = 1;    \
+       } while(0)
+#else
+#define BUILD_BUG_ON __BUILD_BUG_ON
+#endif
+
 #endif