Difference between revisions of "C preprocessor snippets"
Jump to navigation
Jump to search
(add links) |
|||
Line 16: | Line 16: | ||
=== See also === | === See also === | ||
− | * [[ | + | * [[Range-based for loop]] |
* [[incbin()]] | * [[incbin()]] | ||
* [[__is_constexpr()]] | * [[__is_constexpr()]] | ||
+ | * [[X macros]] | ||
[[Category:Programming]] | [[Category:Programming]] | ||
[[Category:C]] | [[Category:C]] |
Revision as of 19:56, 29 February 2020
Check if a macro is set to 1
This works both in #if
preprocessor expressions and in actual C code:
// https://stackoverflow.com/a/10119699/1697183
// https://news.ycombinator.com/item?id=3830609
// https://github.com/torvalds/linux/commit/69349c2dc01c489eccaa4c472542c08e370c6d7e
#define is_set(macro) is_set_(macro)
#define macrotest_1 ,
#define is_set_(value) is_set__(macrotest_##value)
#define is_set__(comma) is_set___(comma 1, 0)
#define is_set___(_, v, ...) v