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

后端 未结 4 823
暖寄归人
暖寄归人 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:09

    According to a quick search it's a bug in MSVC that gets overcame.

    As I understand it,

    for(int i=0...){.....} 
    //later at the same scope level in the same function
    for(int i=0...){...}
    

    will cause a redefinition of 'i' error.

    If the for statement is enclosed in an if statement, the compiler works as it should so that there is no redefinition error(apparently it interprets scope levels of 'if' but not 'for')

提交回复
热议问题