What is the possible use for “#define for if (false) {} else for”?

后端 未结 4 840
暖寄归人
暖寄归人 2020-11-29 05:28

In another question, I just spotted this little pearl of C wisdom:

#define for if (false) {} else for

which caused MSVC to

4条回答
  •  青春惊慌失措
    2020-11-29 06:34

    Because the msvc compiler incorrectly handles the scope of variables declared in the for statement by default. To avoid this behaviour, you had to turn off microsoft extensions which then made the ms headers not compile.

    I use (yes, i still use vs6) a different one which does not cause the warning in vs6, although the Intel compiler still spots it.

    #define for switch(0) case 0: default: for
    

    I can't remember where I got it from, but I doubt that I invented it ;-)

    I know the other answers already say most of this, but the pop-up says to make sure that you answer the question.

提交回复
热议问题