Connecting Tech Pros Worldwide Help | Site Map

Intel C++ 8.0 : declaration hides declaration

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 08:58 AM
Alex Vinokur
Guest
 
Posts: n/a
Default Intel C++ 8.0 : declaration hides declaration

===========
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?

--
Alex Vinokur
mailto:alexvn@connect.to
http://mathforum.org/library/view/10978.html






  #2  
Old July 22nd, 2005, 08:58 AM
Chuck McDevitt
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Alex Vinokur" <alexvn@big.foot.com> wrote in message
news:c4qu9m$2kb9ao$1@ID-79865.news.uni-berlin.de...[color=blue]
> ===========
> 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?
>
> --[/color]

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.




  #3  
Old July 22nd, 2005, 08:58 AM
Chuck McDevitt
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Alex Vinokur" <alexvn@big.foot.com> wrote in message
news:c4qu9m$2kb9ao$1@ID-79865.news.uni-berlin.de...[color=blue]
> ===========
> 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?
>
> --[/color]

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.




  #4  
Old July 22nd, 2005, 08:59 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message
news:Ddccc.78943$JO3.41863@attbi_s04...[color=blue]
>[/color]

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

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


  #5  
Old July 22nd, 2005, 08:59 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message
news:Ddccc.78943$JO3.41863@attbi_s04...[color=blue]
>[/color]

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

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


  #6  
Old July 22nd, 2005, 09:00 AM
Ali Cehreli
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration

"Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message news:<Ddccc.78943$JO3.41863@attbi_s04>...[color=blue]
> "Alex Vinokur" <alexvn@big.foot.com> wrote in message
> news:c4qu9m$2kb9ao$1@ID-79865.news.uni-berlin.de...[color=green]
> > ===========
> > 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?
> >
> > --[/color]
>
> 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.[/color]

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.
[color=blue]
> 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.[/color]

Ali
  #7  
Old July 22nd, 2005, 09:00 AM
Ali Cehreli
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration

"Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message news:<Ddccc.78943$JO3.41863@attbi_s04>...[color=blue]
> "Alex Vinokur" <alexvn@big.foot.com> wrote in message
> news:c4qu9m$2kb9ao$1@ID-79865.news.uni-berlin.de...[color=green]
> > ===========
> > 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?
> >
> > --[/color]
>
> 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.[/color]

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.
[color=blue]
> 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.[/color]

Ali
  #8  
Old July 22nd, 2005, 09:00 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Ali Cehreli" <acehreli@yahoo.com> wrote in message
news:f0070508.0404051315.7c18c916@posting.google.c om...[color=blue]
> "Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message[/color]
news:<Ddccc.78943$JO3.41863@attbi_s04>...

<snip>
[color=blue][color=green]
> >
> > It's a bug. Intel C++ 8.0 is handling the for loop scoping in the[/color][/color]
old way,[color=blue][color=green]
> > where the variable declared in the for loop would still be[/color][/color]
in-scope after[color=blue][color=green]
> > the loop exits.[/color]
>
> I don't have that compiler but I don't think that's the case here.[/color]
If[color=blue]
> that was the case, then I would expect the compiler to emit an error
> saying that 'i' was being redefined.
>[/color]

<snip>
[color=blue]
> 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.[/color]

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


  #9  
Old July 22nd, 2005, 09:00 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Intel C++ 8.0 : declaration hides declaration


"Ali Cehreli" <acehreli@yahoo.com> wrote in message
news:f0070508.0404051315.7c18c916@posting.google.c om...[color=blue]
> "Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote in message[/color]
news:<Ddccc.78943$JO3.41863@attbi_s04>...

<snip>
[color=blue][color=green]
> >
> > It's a bug. Intel C++ 8.0 is handling the for loop scoping in the[/color][/color]
old way,[color=blue][color=green]
> > where the variable declared in the for loop would still be[/color][/color]
in-scope after[color=blue][color=green]
> > the loop exits.[/color]
>
> I don't have that compiler but I don't think that's the case here.[/color]
If[color=blue]
> that was the case, then I would expect the compiler to emit an error
> saying that 'i' was being redefined.
>[/color]

<snip>
[color=blue]
> 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.[/color]

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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.