Re: what's the scope of i ?
From: Ioannis Vranos (ivr_at_guesswh.at.grad.com)
Date: 10/17/04
- Next message: Jim Newton: "Re: Challenge: Triangles puzzle"
- Previous message: Rolf Magnus: "Re: the last one"
- In reply to: Unforgiven: "Re: what's the scope of i ?"
- Next in thread: Unforgiven: "Re: what's the scope of i ?"
- Reply: Unforgiven: "Re: what's the scope of i ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jim Newton: "Re: Challenge: Triangles puzzle"
- Previous message: Rolf Magnus: "Re: the last one"
- In reply to: Unforgiven: "Re: what's the scope of i ?"
- Next in thread: Unforgiven: "Re: what's the scope of i ?"
- Reply: Unforgiven: "Re: what's the scope of i ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|