C preprocessor snippets: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
Content added Content deleted
|  (move to category) Tag: New redirect | |||
| Line 1: | Line 1: | ||
| #REDIRECT [[Category:C preprocessor snippets]] | |||
| === Check if a macro is set to 1 === | |||
| This works both in <code>#if</code> preprocessor expressions and in actual C code: | |||
| <source lang="C"> | |||
| // 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 | |||
| </source> | |||
| === See also === | |||
| * [[Range-based for loop]] | |||
| * [[incbin()]] | |||
| * [[__is_constexpr()]] | |||
| * [[X macros]] | |||
| [[Category:Programming]] | |||
| [[Category:C]] | |||
Latest revision as of 11:58, 1 March 2020
Redirect to: