Intel C++ 8.0 : declaration hides declaration

Discussion in 'C++' started by Alex Vinokur, Apr 5, 2004.

  1. Alex Vinokur

    Alex Vinokur Guest

    ===========
    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:
    http://mathforum.org/library/view/10978.html
     
    Alex Vinokur, Apr 5, 2004
    #1
    1. Advertising

  2. "Alex Vinokur" <> wrote in message
    news:c4qu9m$2kb9ao$-berlin.de...
    > ===========
    > 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.
     
    Chuck McDevitt, Apr 5, 2004
    #2
    1. Advertising

  3. "Chuck McDevitt" <> wrote in message
    news:Ddccc.78943$JO3.41863@attbi_s04...
    >



    >
    > 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
     
    Jonathan Turkanis, Apr 5, 2004
    #3
  4. Alex Vinokur

    Ali Cehreli Guest

    "Chuck McDevitt" <> wrote in message news:<Ddccc.78943$JO3.41863@attbi_s04>...
    > "Alex Vinokur" <> wrote in message
    > news:c4qu9m$2kb9ao$-berlin.de...
    > > ===========
    > > 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.


    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
     
    Ali Cehreli, Apr 5, 2004
    #4
  5. "Ali Cehreli" <> wrote in message
    news:...
    > "Chuck McDevitt" <> wrote in message

    news:<Ddccc.78943$JO3.41863@attbi_s04>...

    <snip>

    > >
    > > 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.
    >


    <snip>

    > 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
     
    Jonathan Turkanis, Apr 5, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reb
    Replies:
    3
    Views:
    3,168
    Anthony Williams
    Nov 27, 2003
  2. Wayne Brantley

    hides inherited member ApplicationInstance

    Wayne Brantley, Dec 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    6,935
    Steven Cheng[MSFT]
    Dec 19, 2005
  3. whatnext
    Replies:
    9
    Views:
    421
  4. Kazik�
    Replies:
    4
    Views:
    1,338
    Jonathan Lee
    Jul 6, 2009
  5. Merciadri Luca
    Replies:
    2
    Views:
    991
    Merciadri Luca
    Nov 2, 2010
Loading...

Share This Page