内联方法名称的 GCC 预处理器
我正在开发一个项目,其中的代码如下:
#define NAME() Array
inline NAME()* NAME()_init (void* arg0){return (NAME()*)Object_init(arg0);}
但我得到以下结果:
inline Array* Array _init (void* arg0){return (Array*)Object_init(arg0);}
“Array”和“_init”之间有空格 因为这是一个函数名称,所以我显然不需要空格。有谁知道怎么把空间弄出来吗?
I'm working on a project where I have code like the following:
#define NAME() Array
inline NAME()* NAME()_init (void* arg0){return (NAME()*)Object_init(arg0);}
But I get the following result:
inline Array* Array _init (void* arg0){return (Array*)Object_init(arg0);}
With a space between the "Array" and the "_init"
Because this is a function name, I obviously do not want the space. Does anyone know how to get the space out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该像这样更改语义:
编辑:至少它可以与 GNU cpp 一起使用。
EDIT2:也尝试过
-ansi -pedantic
,它似乎在没有警告的情况下工作......You should change the semantics in something like this:
EDIT: At least it works with GNU cpp.
EDIT2: tried also with
-ansi -pedantic
and it seemed to work without warning...将两个标记合并为一个的唯一方法(例如,将调用
NAME()
和_init
的结果组合起来)是使用串联运算符 (## )。您需要这样做:
是的,额外的间接级别是必要的< /a>.
请注意,如果不带参数,则不需要使用类似函数的宏,因此您可以轻松使用:
The only way to combine two tokens into one (e.g., to combine the result of invoking
NAME()
and_init
) is to use the concatenation operator (##
). You'll need to do something like so:Yes, the extra level of indirection is necessary.
Note that you don't need to use a function-like macro if you take no parameters, so you could just as easily use: