]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Include macro to allow check for compile time bugs.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 6 Jan 2013 14:02:49 +0000 (15:02 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 6 Jan 2013 14:02:49 +0000 (15:02 +0100)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
ulut/ul_utdefs.h

index 0f45a03612d1a434c408580bd951c5d4a0a4ab4a..9c38fe5b3b2468fc8141999bd541923cb65e6a41 100644 (file)
@@ -17,6 +17,38 @@ extern "C" {
 #define inline _inline
 #endif
 
+#if !defined(UL_BUILD_BUG_ON_MSG_LINE) && defined(__OPTIMIZE__) && \
+  ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
+#define UL_BUILD_BUG_ON_MSG_LINE_EXP1(condition, msg, line) \
+({ \
+  if (!!(condition)) { \
+    void compile_time_bug_on_line_ ## line (void) __attribute__((error(msg))); \
+    compile_time_bug_on_line_ ## line (); \
+  } \
+})
+#define UL_BUILD_BUG_ON_MSG_LINE(condition, msg, line) \
+  UL_BUILD_BUG_ON_MSG_LINE_EXP1(condition, msg, line)
+#endif /*UL_BUILD_BUG_ON_MSG for GCC*/
+
+#ifndef UL_BUILD_BUG_ON_MSG_LINE
+#define UL_BUILD_BUG_ON_MSG_LINE(condition, msg, line) \
+  ((void)sizeof(char[1 - 2*!!(condition)]))
+#endif /*UL_BUILD_BUG_ON_MSG*/
+
+#ifndef UL_BUILD_BUG_ON_MSG
+#define UL_BUILD_BUG_ON_MSG(condition, msg) \
+  UL_BUILD_BUG_ON_MSG_LINE(condition, msg, __LINE__)
+#endif /*UL_BUILD_BUG_ON_MSG*/
+
+#ifndef UL_BUILD_BUG_ON
+#define UL_BUILD_BUG_ON(condition) \
+  UL_BUILD_BUG_ON_MSG(condition, "Build time check " #condition " failed")
+#endif /*UL_BUILD_BUG_ON*/
+
+#if !defined(UL_OFFSETOF) && defined(__GNUC__) && __GNUC__ >= 4
+#define UL_OFFSETOF(_type, _member) __builtin_offsetof(_type, _member)
+#endif /*UL_OFFSETOF*/
+
 #ifndef UL_OFFSETOF
 /* offset of structure field */
 #define UL_OFFSETOF(_type,_member) \