Skip to content

Instantly share code, notes, and snippets.

@thoughtpolice
Created December 8, 2011 22:06
Show Gist options
  • Save thoughtpolice/1448869 to your computer and use it in GitHub Desktop.
Save thoughtpolice/1448869 to your computer and use it in GitHub Desktop.
static_assert omg
#if defined(COMPILER_GNUC) && \
(4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__))
#define STATIC_ASSERT(cond,m) _Static_assert(cond, m)
#else
/* Not GCC 4.6 */
#define STATIC_ASSERT_NAME2(name, line) name ## line
#define STATIC_ASSERT_NAME(line) STATIC_ASSERT_NAME2(jas_assert_, line)
/* The unused 'm' is a transition into C1x _Static_assert */
#ifdef __COUNTER__
#define STATIC_ASSERT(cond,m) \
extern void STATIC_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#else
#define STATIC_ASSERT(cond,m) \
extern void STATIC_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment