scope of variable outside for loop

前端 未结 1 912
栀梦
栀梦 2020-12-21 11:56

I\'m trying to use a program written a few years ago and compiled in a previous version of MS VC++ (I am using VC++ 2008). There are a lot (hundreds) of instances similar t

相关标签:
1条回答
  • 2020-12-21 12:13

    An earlier version of MSVC had this "misfeature" in that it leaked those variables into the enclosing scope.

    In other words, it treated:

    for (int i = 0; i<10; i++) {
        // something using i
    }
    

    the same as:

    int i;
    for (i = 0; i<10; i++) {
        // something using i
    }
    

    See the answers to this question I asked about a strange macro definition, for more detail.

    0 讨论(0)
提交回复
热议问题