In a #define clause, how to make the preprocessor replace a parameter inside a variable name?

后端 未结 1 1099
悲&欢浪女
悲&欢浪女 2021-01-23 13:27

I have the following code:

#define MY_MACRO(PARAM) int PARAM_int; double PARAM_double; [subsequent instructions]

Unfortunately, it does not wor

相关标签:
1条回答
  • 2021-01-23 13:50

    PARAM_int is considered to be a single token, that is distinct from PARAM. You can concatenate tokens in a macro definition with ##:

    #define MY_MACRO(PARAM) int PARAM ## _int; double PARAM ## _double;
    

    Now, PARAM will expand to whatever you invoke the macro with, and then the resulting token will be pasted together with _int and _double.

    0 讨论(0)
提交回复
热议问题