Some C++ questions
Joe Buck
jbuck@synopsys.com
Mon Oct 27 18:32:00 GMT 1997
> Here are a couple of C++ scoping questions I have.
These are both areas where the committee changed the language since
the publication of the ARM.
> 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.
This was a relatively recent addition to the language. It used to be
that you couldn't declare a variable in an if.
> 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.
So is this (in the ARM, the scope of the first i extends through
the rest of the file; the committee changed it).
> Who is right?
SGI and SunPro are no longer right (the language changed and they didn't
keep up).
More information about the Gcc
mailing list