C macro, something weird

后端 未结 2 1490
清歌不尽
清歌不尽 2020-12-22 14:01

Trying to figure out something simple in a C macro, like this code for example:

#include  
#define MACRO(b)  printf(\"%d\\n\", b*b)

int main(         


        
2条回答
  •  情歌与酒
    2020-12-22 15:04

    Put parentheses around your macro to evaluate arguments in the correct order:

    #include  
    #define MACRO(b)  printf("%d\n", (b)*(b))
    
    int main()
    {
        MACRO(4+1); 
    }
    

提交回复
热议问题