strange result on macro expansion

前端 未结 4 1005
误落风尘
误落风尘 2020-12-21 06:46

Consider the following code snippet

#include
#define A -B
#define B -C
#define C 5

int main()
{
  printf(\"The value of A is %d\\n\", A);
  r         


        
4条回答
  •  忘掉有多难
    2020-12-21 07:01

    The preprocessor introduces a space in-between the expansion of B and C:

    #define A -B
    #define B -C
    #define C 5
    A
    

    with output (generated via cpp < test.c)

    # 1 "test.c"
    # 1 "" 1
    # 1 "" 3
    # 329 "" 3
    # 1 "" 1
    # 1 "" 2
    # 1 "test.c" 2
    
    
    
    - -5
    

提交回复
热议问题