Is there a good reason for always enclosing a define in parentheses in C?

后端 未结 9 1123
遇见更好的自我
遇见更好的自我 2020-12-01 02:33

Clearly, there are times where #define statements must have parentheses, like so:

#define WIDTH 80+20

int a = WIDTH * 2; // expect a==200 but a         


        
9条回答
  •  一个人的身影
    2020-12-01 03:27

    Whenever the define consists of a single token (one operand only, no operators), the parentheses are not needed because a single token (such as 100) is an indivisible atom when lexing and parsing.

提交回复
热议问题