这些宏包含或排除文本:
#include <stdio.h>
#define SKIP_TEXT(text)
#define JOIN_TEXT(text) text
int main(void)
{
#define S(TEXT) "a" TEXT("b") "c" TEXT("d")
printf("%s\n", S(SKIP_TEXT));
printf("%s\n", S(JOIN_TEXT));
return 0;
}
输出:
ac
abcd
现在我正在尝试做同样的事情而不定义S
每个要评估的字符串,但我不知道如何替换TEXT
为SKIP_TEXT
orJOIN_TEXT
#include <stdio.h>
#define SKIP_TEXT(text)
#define JOIN_TEXT(text) text
#define S(s) S_EXEC(s)
#define S_EXEC_SKIP(s) s /* Here I want to skip text */
#define S_EXEC_JOIN(s) s /* Here I want to join text */
#define S_EXEC(s) S_EXEC_##s
int main(void)
{
printf("%s\n", S(SKIP("a" TEXT("b") "c" TEXT("d")));
printf("%s\n", S(JOIN("a" TEXT("b") "c" TEXT("d")));
return 0;
}
有什么方法可以评估来自的论点S()
吗?