Visual-C ++和gcc之间的宏##连接运算符的差异 [英] Differences in Macro ## concatenation operator between Visual-C++ and gcc

查看:262
本文介绍了Visual-C ++和gcc之间的宏##连接运算符的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #define STRUCTMEMBER(())()成员,价值)GlobalStructInstance。 ## Member =价值
...
STRUCTMEMBER(Item,1);

这在Visual C ++中完美工作,但gcc 3.4.5(MingGW)产生以下错误: / p>


粘贴。和Item不会给出有效的预处理令牌


当我使用 - >运算符时,也会发生这种情况。我没有发现关于连接的提示,这些操作符的使用是被禁止的。



有人有想法吗?

解决方案

也许Visual C ++将两个空格粘贴在一起以创建另一个空间。不是空格是代币,但它可以让你的代码工作。



object.member 不是一个令牌,它是三个令牌,所以你不需要使用令牌粘贴来实现你描述的宏。只需删除'##',它就可以在任何地方工作。




I'm having a macro like this ( not exactly, but function is quite equivalent):

#define STRUCTMEMBER(Member,Value) GlobalStructInstance. ## Member = Value
...
STRUCTMEMBER(Item,1);

This works perfectly in Visual C++, but gcc 3.4.5 (MingGW) yield the following error:

pasting "." and "Item" does not give a valid preprocessing token

This also happens when I use the "->" operator. I didn't found hints on concatenation, that the usage of these operators is forbidden.

Does anyone have an idea ?

解决方案

Maybe Visual C++ is pasting a couple of spaces together to make another space. Not that whitespaces are tokens, but it would allow your code to work.

object.member is not a token, it's three tokens, so you don't need token-pasting to implement the macro you describe. Just remove the '##' and it should work everywhere.

[Edit: just checked, and the result of using ## to form something that isn't a valid token is undefined. So GCC is allowed to reject it and MSVC is allowed to ignore it and perform no paste, as far as I can tell.]

这篇关于Visual-C ++和gcc之间的宏##连接运算符的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆