Alan Carre - 2013-05-09

It is not an issue in VS11 and hasn't been since Visual Studio 2005. The "buggy for" refers to improper scoping of variables declared in the for loop declaration:

ex:
/////////////////////////////
//Buggy for loop example:
//
//THE FOLLOWING SHOULD NOT COMPILE!
//=================================
//But it does in VC6 which is non-compliant.
//The output would be "10" in that case.
/////////////////////////////
#include <stdio.h>

int main(int, ...) {
for(int i=0;i<10;i++) {/* can access i in here ONLY */}
return printf("%d", i);
}

The variable "i" should only be available inside the scope of the for loop.

So if you replace "for" with if(1) for ...

if(1) for(int i=0;i<10;i++) {}

really looks like:

if(1) {
for(int i=0;i<10;i++) {
//do some stuff
}
}

i is not available here because it falls within case "1" (there is an invisible scope).

==================

At least that's my best guess. Not sure how to test it on a compliant compiler.

  • Alan Carre
 
Last edit: Alan Carre 2013-05-09