C/C++ #define Macro inside macro?

前端 未结 4 1159
無奈伤痛
無奈伤痛 2021-01-18 13:04

I would like something like:

#define C_OR_CPP(C__, CPP__) #ifdef __cplusplus\\
CPP__\\
#else\\
C__\\
#endif

Is it possible? Maybe some dirt

4条回答
  •  天涯浪人
    2021-01-18 13:52

    AProgrammer already given you the right answer, but the answer to the "is it possible" part of the question is no. Macro expansion doesn't occur until after all preprocessor directives have been handled, so any macro that expands into a #define or #ifdef will be passed to the compiler as regular source text, which will cause the compiler to yak.

提交回复
热议问题