Problem with Macros

后端 未结 4 1073
轻奢々
轻奢々 2020-12-06 13:40

HI ,

Can some one help me in understanding why the value of SQUARE(x) is 49 ?

I am using Visual C++ 6.0 .

#define SQUARE(X) X * X

int main(i         


        
4条回答
  •  再見小時候
    2020-12-06 14:26

    Because the macro expands to:

    ++y * ++y
    

    which gives undefined behaviour in C++ - the result could be anything. This very well known problem should be covered in any decent textbook that covers the use of macros. Which one are you using?

提交回复
热议问题