相当于定义名称中的 hash-hash
在#define
中,可以使用A ## B
将预处理器变量和定义连接到标识符。
#define ADD_UNDERSCORE(X) X##_
/* ADD_UNDERSCORE(n) -> n_ */
#define 是否有等效的左侧?例如
#define A a
#define B b
#define A##B(X) X
/* ab(n) -> n */
In a #define
one can use A ## B
to concatenate preprocessor variables and defines to an identifier.
#define ADD_UNDERSCORE(X) X##_
/* ADD_UNDERSCORE(n) -> n_ */
Is there an equivalent leftside of the #define? E.g.
#define A a
#define B b
#define A##B(X) X
/* ab(n) -> n */
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以。在宏定义中,
define
后的第一个标记必须是标识符 ((草案)ISO/IEC 9899;1999,6.10,第 149 页)。#define
指令没有其他预处理可以从其他内容中生成标识符。该标准特别规定 (6.10.3):并且宏名称没有注明“否则”。
No. In a macro definition, the first token after the
define
has to be an identifier ((draft) ISO/IEC 9899;1999, 6.10, page 149).There is no other preprocessing of the
#define
directives which could make an identifier out of something else. In particular, the standard specifies (6.10.3):And it isn't stated "otherwise" for the macro name.