[sheepdog] [PATCH 1/2] util: add BUILD_BUG_ON() for detecting errors at compile time

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Mar 19 05:03:46 CET 2013


This patch adds BUILD_BUG_ON() to include/util.h. The macro can be
used for detecting errors which should cause build
error. e.g. breaking alignment of some structs.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/util.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/util.h b/include/util.h
index 5a72bd1..2f6046e 100644
--- a/include/util.h
+++ b/include/util.h
@@ -152,4 +152,7 @@ static inline bool is_stdout_console(void)
 	return isatty(STDOUT_FILENO);
 }
 
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(condition) ((void)sizeof(struct { int: -!!(condition); }))
+
 #endif
-- 
1.7.2.5




More information about the sheepdog mailing list