Visual .NET not complaining on a C++ semantic error

L

lamthierry

I have the following piece of codes:


for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();


Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

Thanks
Thierry
 
V

Victor Bazarov

I have the following piece of codes:


for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();


Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

You need to learn to use your compiler better. By default it has this
"feature" as an "extension". Disable language extensions and you'll get
an error message. Also, consider asking compiler-specific questions in
a newsgroup for that compiler (microsoft.public.vc.language, here)

V
 
B

Bob Hairgrove

I have the following piece of codes:


for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();


Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

Thanks
Thierry

There have been many times when I wished I could redefine "I" globally
elsewhere...<g>.

Seriously, though, I would first look for a compiler switch which
turns off the ANSI "for" scope rules regarding the above.

Secondly, I suspect pollution of the global namespace as the culprit.
I would look for any header files, included either directly or
indirectly by your own headers (but including your own headers) which
have "using namespace <whatever>;" in them. One of these MIGHT have
declared "i" at global scope within the local namespace or else at
global scope.

Other than that -- well, perhaps you *did* declare an "i" (or was it
an "I"?? <g>) somewhere at global scope...
 
K

Karl Heinz Buchegger

I have the following piece of codes:

for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();

Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler switch.

AFAIK, later versions of VC compilers changed that.
 
G

Guest

Im using 2005b2, default config

error C2065: 'i' : undeclared identifier

you have prob messed up something. vs isnt so ...stupid ;)
 
M

Maxim Yegorushkin

Karl Heinz Buchegger wrote:

[]
Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler switch.

Visual C++ 6.0 does not have a switch for that.

The usual solution for this compiler was:

#define for if(0); else for
 
V

Victor Bazarov

Maxim said:
Karl Heinz Buchegger wrote:

[]
Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler
switch.

Visual C++ 6.0 does not have a switch for that.

Actually, it does. It's called "Disable Language extensions". OT here,
but still. Of course, it causes all kinds of trouble if you try to use
some other MS libraries...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top