scope of a variable declared in a for loop
Hello all code gurus,
Here is another issue which has bothered me for years.
One poor soul dared to ask a while ago and the thread turned ugly --- with authors radically defending one development environment over the other and such things.
So please here just try to stick to the C++ language specification.
What is the scope of a loop variable?
I was of the opinion that the scope of i (see code snippet below) must be limited to lines within the loop.
Some compilers exhibit different behavior regarding this syntax.
Can anyone verify the proper language specification here?
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
for(register int i = 0; i < 10; i++)
{
cout << i << endl;
}
#ifdef __GNUC__
#else
// This line should not compile in my opinion.
cout << i << endl;
#endif
return 1;
}
Thanks. Don't get too rowdy...
Chris.
You're gonna go blind staring into that box all day.