相当于定义名称中的 hash-hash

发布于 2024-12-12 09:32:52 字数 279 浏览 4 评论 0原文

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骑趴 2024-12-19 09:32:52

不可以。在宏定义中,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):

The preprocessing tokens within a preprocessing directive are not subject to macro
expansion unless otherwise stated.

And it isn't stated "otherwise" for the macro name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文