Created
April 9, 2016 05:27
-
-
Save mlabbe/e2c26c9a54ed4d05bc49c06388473522 to your computer and use it in GitHub Desktop.
C89 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
// usage: FTG_STATIC_ASSERT(1==0) | |
// error message contains "assertion_at_line_xxx" | |
// | |
// usage: FTG_STATIC_ASSERT_MSG(1==0, one_is_not_zero) | |
// error message contains: "one_is_not_zero" | |
// | |
// tested on GCC, Clang, MSVC 98 and MSVC 2015 | |
// | |
#define FTG_STATIC_ASSERT_MSG(x, msg) typedef int FTG__StaticAssert_##msg[(x) ? 1 : -1] | |
#define FTG__STATIC_ASSERT_3(x,L) FTG_STATIC_ASSERT_MSG(x, assertion_at_line_##L) | |
#define FTG__STATIC_ASSERT_2(x,L) FTG__STATIC_ASSERT_3(x,L) | |
#define FTG_STATIC_ASSERT(x) FTG__STATIC_ASSERT_2(x,__LINE__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment