C preprocessor snippets: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(new page) |
(add links) |
||
Line 13: | Line 13: | ||
#define is_set___(_, v, ...) v |
#define is_set___(_, v, ...) v |
||
</source> |
</source> |
||
=== See also === |
|||
* [[X macros]] |
|||
* [[incbin()]] |
|||
* [[__is_constexpr()]] |
|||
[[Category:Programming]] |
[[Category:Programming]] |
Revision as of 14:27, 25 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