error: pasting “.” and “red” does not give a valid preprocessing token

后端 未结 1 678
既然无缘
既然无缘 2021-02-11 13:13

I\'m implementing The X macro, but I have a problem with a simple macro expansion. This macro (see below) is used into several macros usage examples, by including in this articl

相关标签:
1条回答
  • 2021-02-11 14:00

    . separates tokens and so you can't use ## as .red is not a valid token. You would only use ## if you were concatenating two tokens into a single one.

    This works:

    #define X(a, b) foo.a = -1;
    

    What's a valid proprocessing token? Can someone explain this?

    It is what gets parsed/lexed. foo.bar would be parsed as 3 tokens (two identifiers and an operator): foo . bar If you use ## you would get only 2 tokens (one identifier and one invalid token): foo .bar

    0 讨论(0)
提交回复
热议问题