Intel C++ 8.0 : declaration hides declaration

A

Alex Vinokur

===========
Windows 2000
Intel C++ 8.0
===========

------ foo.cpp ------
int main ()
{
for (int i = 0; i < 10; i++);
for (int i = 0; i < 10; i++);
return 0;
}
---------------------

--- Compilation ---

$ icl foo.cpp

Intel(R) C++ Compiler for 32-bit applications, Version 8.0 Build 20031017Z Package ID: W_CC_P_8.0.040
Copyright (C) 1985-2003 Intel Corporation. All rights reserved.
30 DAY EVALUATION LICENSE

foo.cpp
icl: NOTE: The evaluation period for this product ends on 16-apr-2004 UTC.
foo.cpp(4): warning #1420: declaration in for-initializer hides a declaration in the surrounding scope
the hidden declaration is at line 3
for (int i = 0; i < 10; i++);
^

foo.cpp(4): warning #1429: variable declaration hides declaration in for-initializer
the hidden declaration is at line 3
for (int i = 0; i < 10; i++);
^

Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation. All rights reserved.

-out:foo.exe
foo.obj
 
C

Chuck McDevitt

Alex Vinokur said:
===========
Windows 2000
Intel C++ 8.0
===========

------ foo.cpp ------
int main ()
{
for (int i = 0; i < 10; i++);
for (int i = 0; i < 10; i++);
return 0;
}
---------------------

--- Compilation ---

$ icl foo.cpp

Intel(R) C++ Compiler for 32-bit applications, Version 8.0 Build
20031017Z Package ID: W_CC_P_8.0.040
Copyright (C) 1985-2003 Intel Corporation. All rights reserved.
30 DAY EVALUATION LICENSE

foo.cpp
icl: NOTE: The evaluation period for this product ends on 16-apr-2004 UTC.
foo.cpp(4): warning #1420: declaration in for-initializer hides a
declaration in the surrounding scope
the hidden declaration is at line 3
for (int i = 0; i < 10; i++);
^

foo.cpp(4): warning #1429: variable declaration hides declaration in
for-initializer
the hidden declaration is at line 3
for (int i = 0; i < 10; i++);
^

Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation. All rights reserved.

-out:foo.exe
foo.obj

-------------------

Why does Intel C++ 8.0 produce the warnings?

--

It's a bug. Intel C++ 8.0 is handling the for loop scoping in the old way,
where the variable declared in the for loop would still be in-scope after
the loop exits.
Microsoft Visual C++ used to do this as well, and still does it if you don't
tell it you want "Conforming" behaviour for for-loops. Perhaps Intel C++
8.0 has an option for this?

Anyway, you can always add extra braces:

int main ()
{
{for (int i = 0; i < 10; i++);}
{for (int i = 0; i < 10; i++);}
return 0;
}

That will make the warning go away.
 
J

Jonathan Turkanis

Chuck McDevitt said:
It's a bug. Intel C++ 8.0 is handling the for loop scoping in the old way,
where the variable declared in the for loop would still be in-scope after
the loop exits.
Microsoft Visual C++ used to do this as well, and still does it if you don't
tell it you want "Conforming" behaviour for for-loops. Perhaps Intel C++
8.0 has an option for this?

Here are the relevant options, from the Intel manual:

/Zc:forScope - enforce standard behavior for initializers of loops
/Za - Enforces strict conformance to the ANSI standard
for C
/Qms0 - Instructs the compiler to disable Microsoft
compatibility bugs.

Jonathan
 
A

Ali Cehreli

Chuck McDevitt said:
It's a bug. Intel C++ 8.0 is handling the for loop scoping in the old way,
where the variable declared in the for loop would still be in-scope after
the loop exits.

I don't have that compiler but I don't think that's the case here. If
that was the case, then I would expect the compiler to emit an error
saying that 'i' was being redefined.

The fact that it's a warning about hiding a varible in the surrounding
scope, maybe the compiler gets the code as

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

But the original poster did show a semicolon after the first for loop.
(?)

Also, if the cryptic code at the original poster's output tells us
that the compiler is from 2003, I would be very much surprised if
Intel didn't get that behavior right already at that time.
Microsoft Visual C++ used to do this as well, and still does it if you don't
tell it you want "Conforming" behaviour for for-loops. Perhaps Intel C++
8.0 has an option for this?

Anyway, you can always add extra braces:

int main ()
{
{for (int i = 0; i < 10; i++);}
{for (int i = 0; i < 10; i++);}
return 0;
}

That will make the warning go away.

Ali
 
J

Jonathan Turkanis

Ali Cehreli said:
I don't have that compiler but I don't think that's the case here. If
that was the case, then I would expect the compiler to emit an error
saying that 'i' was being redefined.

Also, if the cryptic code at the original poster's output tells us
that the compiler is from 2003, I would be very much surprised if
Intel didn't get that behavior right already at that time.

The code compiles on Intel 8.0 for windows with the command-line
option /Zc:forScope, but not without it.

Intel for Windows can be highly conformant if you use the right
options, but by default it has a lot of microsoft compatibility stuff.
Of course microsoft has gotten much better, too, but you still need to
explicitly disable 'microsoft extensions' if you want to approach ISO
conformance.

Jonathan
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top