Skip to content

Instantly share code, notes, and snippets.

@leiless
Last active November 30, 2018 02:30
Show Gist options
  • Save leiless/941d26b9d36da87fdfd1dc5c922acfd0 to your computer and use it in GitHub Desktop.
Save leiless/941d26b9d36da87fdfd1dc5c922acfd0 to your computer and use it in GitHub Desktop.
Simplified BUILD_BUG_ON(condition) macro
#ifdef DEBUG
#define BUILD_BUG_ON(cond) ((void) sizeof(char[-!(cond)]))
#define BUILD_BUG_ON2(cond) ((void) (char[1]){[!(cond)] = 0}) /* Nonoptimal */
#else
#define BUILD_BUG_ON(cond) ((void) (cond))
#define BUILD_BUG_ON2(cond) ((void) (cond))
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment