Tag: 嵌套的

C预处理器宏是否可以包含预处理程序指令?

我想做相同的以下内容: #define print_max(TYPE) \ # ifdef TYPE##_MAX \ printf(“%lld\n”, TYPE##_MAX); \ # endif print_max(INT); 现在,只要我在函数宏中看到,就不允许使用#ifdef或任何嵌套的预处理器指令。 有任何想法吗? 更新:所以看起来这是不可能的。 即使是在运行时检查的黑客也无法实现。 所以我想我会选择以下内容: #ifndef BLAH_MAX # define BLAH_MAX 0 #endif # etc… for each type I’m interested in #define print_max(TYPE) \ if (TYPE##_MAX) \ printf(“%lld\n”, TYPE##_MAX); print_max(INT); print_max(BLAH);