Created
December 10, 2012 03:42
-
-
Save enjoylife/4248265 to your computer and use it in GitHub Desktop.
static assert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define ASSERT_CONCAT_(a, b) a##b | |
| #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) | |
| /* These can't be used after statements in c89. */ | |
| #ifdef __COUNTER__ | |
| #define STATIC_ASSERT(e,m) \ | |
| { enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }; } | |
| #else | |
| /* This can't be used twice on the same line so ensure if using in headers | |
| * that the headers are not included twice (by wrapping in #ifndef...#endif) | |
| * Note it doesn't cause an issue when used on same line of separate modules | |
| * compiled with gcc -combine -fwhole-program. */ | |
| #define STATIC_ASSERT(e,m) \ | |
| { enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }; } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment