Differences in Macro ## concatenation operator between Visual-C++ and gcc

后端 未结 3 1117
梦谈多话
梦谈多话 2020-12-19 11:54

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

#define STRUCTMEMBER(Member,Value) GlobalStructInstance. ## Member = Value
..         


        
3条回答
  •  情深已故
    2020-12-19 12:55

    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.]

提交回复
热议问题