Created
August 12, 2011 01:48
-
-
Save cpylua/1141265 to your computer and use it in GitHub Desktop.
C Compile Time 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 COMPILE_TIME_ASSERT(expr) char UNIQUE_NAME[(expr) ? 1 : -1] | |
| #define UNIQUE_NAME MAKE_NAME(__LINE__) | |
| #define MAKE_NAME(line) MAKE_NAME2(line) | |
| #define MAKE_NAME2(line) constraint_ ## line | |
| COMPILE_TIME_ASSERT(sizeof(int) * 8 >= 64); | |
| #ifndef CASSERT | |
| #define CASSERT( exp, name ) typedef int dummy##name [ (exp ) ? 1 : -1 ]; | |
| #endif | |
| CASSERT( sizeof(int) == 2, int_t_is_not_two_bytes ) | |
| #define MS_C_ASSERT(e) typedef char __MS_C_ASSERT__[(e)?1:-1] | |
| MS_C_ASSERT(sizeof(int) < 4); | |
| MS_C_ASSERT(sizeof(int) < 4); // redefinition | |
| #define C_ASSERT(e) extern char __CASSERT__[(e)?1:-1] | |
| C_ASSERT(sizeof(int) < 4); | |
| C_ASSERT(sizeof(int) < 4); | |
| C_ASSERT(sizeof(int) < 4); | |
| C_ASSERT(sizeof(int) < 4); | |
| C_ASSERT(sizeof(int) < 4); | |
| C_ASSERT(sizeof(int) < 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment