c - 带有哈希的预处理器指令

标签 c c-preprocessor preprocessor-directive

#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}

此代码给出输出 100,但如果实现预处理器,printf 将被重写为:

printf("%d",var##12);

那么,输出是怎么来的呢?

最佳答案

双哈希 ##token pasting operator的预处理器。 printf 将被重写为:

printf("%d",var12); // No double-hash

The double-number-sign or "token-pasting" operator (##), which is sometimes called the "merging" operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token and therefore cannot be the first or last token in the macro definition.

关于c - 带有哈希的预处理器指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16739695/

相关文章:

c= (getchar() != EOF)

c - 如何在不退出黑屏的情况下进行另一次计算?

c++ - 如何通过预处理器指令检查程序是否需要 Visual C++ 中的预编译头文件?

c - 忽略空的可变参数

c - 为什么当前宏会返回值14?

c - 了解格式字符串漏洞利用

c - 如何修复这个简单的 C 溢出?

c++ - 编译器找不到预处理器指令(定义)

c++ - 将#elif 与#ifdef 一起使用是否合法?

c - #line 指令和实际用法