Re: what's the scope of i ?

From: Ioannis Vranos (ivr_at_guesswh.at.grad.com)
Date: 10/17/04


Date: Sun, 17 Oct 2004 14:24:12 +0300

Unforgiven wrote:
> "Ioannis Vranos" <ivr@guesswh.at.grad.com> wrote in message
> news:1098008738.444962@athnrd02...
>
>>Unforgiven wrote:
>>
>>
>>>Which is available free (the compiler anyway, not the GUI), at
>>>http://msdn.microsoft.com/visualc/vctoolkit2003/
>>>
>>>Anyway, you'd still need to zet either /Za or /Zc:forScope to get
>>>standards-compliant behaviour.
>
>
> int main()
> {
> for(int i=0; i<10; ++i)
> ;
>
> i = 4; // Should cause error, i not in scope
>
> for(int i=0; i<10; ++i)
> ;
> }
>
> G:\My Documents>cl test.cpp
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
> Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
>
> test.cpp
> Microsoft (R) Incremental Linker Version 7.10.3077
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> /out:test.exe
> test.obj
>
> G:\My Documents>cl test.cpp /Zc:forScope
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
> Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
>
> test.cpp
> test.cpp(6) : error C2065: 'i' : undeclared identifier
>
> G:\My Documents>cl test.cpp /Za
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
> Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
>
> test.cpp
> test.cpp(6) : error C2065: 'i' : undeclared identifier

Yes, the key is this:

/Ze enable extensions (default)

/Za disable extensions (implies /Op)

C:\c>cl /Za temp.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

temp.cpp
temp.cpp(6) : error C2065: 'i' : undeclared identifier

C:\c>

I guess in the default mode, the compiler auto-detects the old style
code and accepts it. For example the following does not produce any errors:

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

   int i = 4;

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

However in the OP compiler it does, as even his simpler code with two
loops refused to compile.

-- 
Ioannis Vranos
http://www23.brinkster.com/noicys


Relevant Pages

  • Re: [STL] How to use set_intersection
    ... > I want to use set_intersection, and the compiler passed with a warning. ... > int main{ ... Copyright Microsoft Corporation 1984-2002. ...
    (microsoft.public.vc.stl)
  • Re: linker error information is missing
    ... Vladimir ... > int main{ ... > Copyright Microsoft Corporation. ... > (the same when I build my applicatoin from VS 2003, all detailed compiler ...
    (microsoft.public.vc.language)
  • Re: whats the scope of i ?
    ... >> Which is available free (the compiler anyway, not the GUI), at ... int main ... Copyright Microsoft Corporation 1984-2002. ...
    (comp.lang.cpp)
  • Re: Bit-related question
    ... Subtraction is addition of a number that has been negated. ... complement signed ints, negation consists of adding one to the one's ... int main ... Copyright Microsoft Corporation 1984-2002. ...
    (microsoft.public.vc.language)
  • Re: sizeof on arrays and pointers
    ... >compilers I am using: ... >int main ... Here is a copy of my Whidbey beta compile session and output for this ... Copyright Microsoft Corporation. ...
    (microsoft.public.vc.language)