Skip to contentSkip to conversation

change BUILD_BUG_ON()

PATCH New Jan Beulich 1 participant 1 message Dec 11, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 change BUILD_BUG_ON()

As was noticed on the Linux side, using an array here isn't appropriate if the condition is not a compile time constant - gcc allows such arrays, and hence the intended effect of producing a compiler error is not achieved in that case. Bit field widths do not know similar language extensions, and hence always produce a compiler error.

xen/include/xen/lib.h +1 -1
@@ -16,7 +16,7 @@ void __warn(char *file, int line);
 #define WARN_ON(p) do { if (p) WARN(); } while (0)
 
 /* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
+#define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
 
 #ifndef assert_failed
 #define assert_failed(p)                                        \