C #define macros

后端 未结 7 1389
情书的邮戳
情书的邮戳 2020-12-21 06:59

Here is what i have and I wonder how this works and what it actually does.

#define NUM 5
#define FTIMES(x)(x*5)

int main(void) {
    int j = 1;
    printf(\         


        
7条回答
  •  抹茶落季
    2020-12-21 07:05

    Since it hasn't been mentioned yet, the way to fix this problem is to do the following:

    #define FTIMES(x) ((x)*5)
    

    The parentheses around x in the macro expansion prevent the operator associativity problem.

提交回复
热议问题