[Sunhelp] ?: a great different compiling between C++ 4.1 and C++ 5.0

Walter Krumshyn wallyk at nortelnetworks.com
Wed Dec 22 00:55:02 CST 1999


I came across this in a C++ tutorial which may answer your question...

In Visual C++ 6.0, a counter which is declared within a for 
loop expression remains in scope after the loop has finished 
executing. However, I recommend that you don't write programs 
that rely on the scope of the counter extending beyond the 
end of the loop. This is because the final draft of the new 
ANSI/ISO standard for C++ says that the scope of the loop 
counter should not extend beyond the end of the loop itself; 
something which is likely to be implemented by future C++ 
compilers. If you need to use the value in the counter after 
the loop has executed, then declare the counter outside the 
scope of the loop.


Regards,

Walter




Wonkyu Chang - Sun Korea SE wrote:
> 
> Dear experts,
> 
> When my customer compiled the some source code with C++ compiler,
> he got quite different results.
> 
> The details was described as followings, the source code was
> extracted as a part of original critical source.
> 
> What do you think about it?
> 
> The following is C++ source code with "src.cpp" as file name.
> 
> [cnt01:/export/home/koscom] cat src.cpp
> #include <stdio.h>
> 
> int main()
> {
>     for(int i =0; i<10; i++) {
>         printf("test[%d]\n", i);
>     }
>     for(i =0; i<10; i++) {
>         printf("sssssss[%d]\n", i);
>     }
>     printf("aaaaaaaaaaa[%d]\n", i);
> }
> 
> He compiled it with C++ 4.1 compiler,
> and get the results as like followings.
> 
> [cnt01:/export/home/koscom] CC -o out1 src.cpp
> [cnt01:/export/home/koscom] out1
> test[0]
> test[1]
> test[2]
> test[3]
> test[4]
> test[5]
> test[6]
> test[7]
> test[8]
> test[9]
> sssssss[0]
> sssssss[1]
> sssssss[2]
> sssssss[3]
> sssssss[4]
> sssssss[5]
> sssssss[6]
> sssssss[7]
> sssssss[8]
> sssssss[9]
> aaaaaaaaaaa[10]
> 
> But, when he compiled it with C++ 5.0,
> and he got the below error message.
> 
> [SVP:/usr5/astock] CC -o out2 src.cpp
> "1.cpp", line 8: Error: i is not defined.
> "1.cpp", line 8: Error: i is not defined.
> "1.cpp", line 8: Error: i is not defined.
> "1.cpp", line 9: Error: i is not defined.
> "1.cpp", line 11: Error: i is not defined.
> 5 Error(s) detected.
> 
> Thanks in advance,
> WK Chang
> 
> _______________________________________________
> SunHELP maillist  -  SunHELP at sunhelp.org
> http://www.sunhelp.org/mailman/listinfo/sunhelp






More information about the SunHELP mailing list