chiark / gitweb /
macro: change assert_cc() so that it can appear outside of functions
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Nov 2013 00:10:22 +0000 (01:10 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Nov 2013 18:36:14 +0000 (19:36 +0100)
src/shared/macro.h

index 9e94495..37cdff1 100644 (file)
@@ -143,19 +143,9 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
         } while (false)
 
 #if defined(static_assert)
-#define assert_cc(expr)                         \
-        do {                                    \
-                static_assert(expr, #expr);     \
-        } while (false)
+#define assert_cc(expr) static_assert(expr, #expr)
 #else
-#define assert_cc(expr)                         \
-        do {                                    \
-                switch (0) {                    \
-                case 0:                         \
-                case !!(expr):                  \
-                        ;                       \
-                }                               \
-        } while (false)
+#define assert_cc(expr) struct _assert_struct_ ## __LINE__ { char x[(expr) ? 0 : -1]; }
 #endif
 
 #define assert_return(expr, r)                    \