Strange behavior of Macro-expansion

前端 未结 3 1123
悲&欢浪女
悲&欢浪女 2020-12-12 01:47

Here\'s the code:

#include 
#include 
#define VAL1(a,b)    a*b
#define VAL2(a,b)    a/b
#define VAL3(a,b)    ++a%b
int main()
{         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-12 01:59

    In one case you have + ++ and in the other case you have ++ +. + ++ and ++ + are different streams of tokens. Macro pasting doesn't change tokenization because it's tokens that are pasted.

    If you punch your program into a C pre-processor, you'll get this out for that line:

    int result = a/d/e*b+ ++c%d;
    

    Notice that the preprocessor had to insert a space because one is mandatory between a + token and a ++ token.

提交回复
热议问题