#define xstr(s) str(s)
#define str(s) #s
#define foo 4
str (foo)
==> "foo"
xstr (foo)
==> xstr (4)
==> str (4)
==> "4"
# work as Stringification symbol in above sample which could be very useful in some cases.
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
WARN_IF (x == 0);
==> do { if (x == 0)
fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
Stringification in C
解析C++预处理器指令:定义、作用及应用实例
最新推荐文章于 2025-04-24 15:06:17 发布
本文深入探讨了C++预处理器指令的定义与用途,并通过具体示例展示了如何使用这些指令进行代码的优化与错误预防。重点介绍了#define, #ifdef, #ifndef, #if, #else, #endif等关键字的功能及其在实际编程中的应用。
741

被折叠的 条评论
为什么被折叠?



