【发布时间】:2010-08-20 19:09:07
【问题描述】:
我正在阅读 phoneME 的源代码。这是一个 FOSS JavaME 实现。它是用 C++ 编写的,我偶然发现了这个:
// Makes a string of the argument (which is not macro-expanded)
#define STR(a) #a
我知道 C 和 C++,但我从未读过这样的东西。 #a 中的# 有什么作用?
另外,在同一个文件中,还有:
// Makes a string of the macro expansion of a
#define XSTR(a) STR(a)
我的意思是,定义一个新宏有什么用,如果它所做的只是调用一个现有的宏?
源代码在https://phoneme.dev.java.net/source/browse/phoneme/releases/phoneme_feature-mr2-rel-b23/cldc/src/vm/share/utilities/GlobalDefinitions.hpp?rev=5525&view=markup。您可以使用 CTRL+F 找到它。
【问题讨论】:
-
显然这(特别是
STR和XSTR宏的组合)被称为“双重字符串化技巧”。问题How, exactly, does the double-stringize trick work?中有很好的解释
标签: c++ c c-preprocessor