C/C++ #define Macro inside macro?

前端 未结 4 1181
無奈伤痛
無奈伤痛 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:48

    Not in C++. But you can

    #ifdef __cplusplus
    # define CPP
    #else
    # define C
    #endif
    

    I assume this is just a pathological example by you. Note also that double underscore is reserved to library implementors (see 17.6.4.3.2 Global names).

    vector, but in C i want it to simply be void, you know.

    So, what speaks against a solution like

    struct Foo {
      #ifdef __cplusplus
      ...
      #else
      ...
      #endif
    };
    

    or what speaks against providing different APIs for different programming languages?

提交回复
热议问题