Some C++ questions
Torbjorn Lindgren
tl@funcom.no
Tue Oct 28 03:03:00 GMT 1997
On Tue, 28 Oct 1997, Ross Alexander wrote:
> Here are a couple of C++ scoping questions I have.
As other have said, comp.lang.c++.moderated...
> 1)
> int main()
> {
> if (int i = 10)
> i++; // should be okay
> i++; // shold be out of scope
> }
>
> SGI CC v7.0 doesn't like the declaration within the if statement.
That's the problem with using an outdated compiler :-)
SGI CC 7.0 is two releases back from the current version (7.1/7.2), and at
least 7.2 which I have handles this correctly, with the options I use (see
below).
> 2)
> int main()
> {
> for (int i = 0; i < 10; i++)
> cout << i;
>
> for (int i = 0; i < 10; i++) // should be fine
> cout << i;
> }
> Both SGI CC v7.0 and SunPro CC 4.2 barf horribly at this.
SGI CC 7.2 with the options I use handles it correctly (CC -n32
-LANG:ansi-for-init-scope=on).
At least SGI *has* a modern compiler (Sun hasn't AFAIK), actually MIPSPro
7.2 is quite good, typical for a modern EDG based compiler (other
examples are Kai C++).
--
Torbjörn Lindgren
E-mail: tl@funcom.com
If Santa ever DID deliver presents on Christmas Eve, he's dead now.
More information about the Gcc
mailing list