[Sunhelp] ?: a great different compiling between C++ 4.1 and C++ 5.0
zahoor at omantel.net.om
zahoor at omantel.net.om
Tue Dec 21 18:09:36 CST 1999
In line 8 (the second "for" loop), you are not defining the variable i. You
have to define it again, just like the first "for" loop. When the first for
loop gets over, the variable i is out of scope.
The reason it was working for ver 4.1 is probably because the compiler was
implicitly defining it as an int for you (some compilers do.) Ver 5.0 seems
more fussy ;-)
If you want to avoid declaring variable "i" over and over again try this:
int main()
{
int i;
for(i =0; i<10; i++) {
printf("test[%d]\n", i);
}
for(i =0; i<10; i++) {
printf("sssssss[%d]\n", i);
}
:
:
:
However, you must remember that in this fashion, space for i is reserved
until the program exits. :-)
Zahoor Alam
zahoor at gto.net.om
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Wonkyu Chang - Sun Korea SE wrote:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>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
:
:
:
>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.
:
:
More information about the SunHELP
mailing list