我尝试保存变量名称,如下所示:
#define TEST someVariable
#define makeString(x) #x
int main(int argc, char *argv[])
{
char TEST[] = makeString(TEST);
printf("%s %s\n", TEST, makeString(TEST));
return 0;
}
输出是:
appden4ik@appDen4ik:/opt/preprocessor/Debug$ ./preprocessor
TEST TEST'
我想要下一个输出:
someVariable someVariable
我哪里错了?
答案 0 :(得分:0)
#include <stdio.h>
#define TEST variable
#define makeStr(x) #x
#define makeString(x) makeStr(x)
int main(int argc, char *argv[]) {
char TEST[] = makeString(TEST);
printf("%s %s\n", TEST, makeString(TEST));
return 0;
}
这有帮助