Making something both a C identifier and a string?

前端 未结 2 1635
攒了一身酷
攒了一身酷 2020-12-13 10:49

Say you want to generate a matched list of identifiers and strings

enum
{
NAME_ONE,
NAME_TWO,
NAME_THREE
};

myFunction(NAME_ONE, \"NAME_ONE\");
myFunction(N         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 11:37

    For your second #define, you need to use the # preprocessor operator, like this:

    #define myDefine(a) myFunc(a, #a);
    

    That converts the argument to a string.

提交回复
热议问题