undefined?
Eiso AB
E.Ab@chem.rug.nl
Fri Aug 25 05:07:00 GMT 2000
please try this program
#include <stdio.h>
void main() {
int i = 2;
printf("%d\n", i++ * i++);
printf("%d\n", i);
}
I know that i++ * i++ is undefined, but afterwards the value of i
should still be defined ( I think) and equal to 4
but the behaviour in gcc-2.8.1 the behaviour is optimiser dependant.
% gcc x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
4
3
% gcc -O1 x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
4
4
Also, although there's is again undefined behaviour involved, I think it's
strange
that both print statements should give the same result, in the program below.
#include <stdio.h>
void main() {
int b = 6;
b+=b++;
printf("%d\n",b);
b=6;
printf("%d\n",b += b++);
}
% gcc x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
7
12
% gcc -O2 x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
13
12
regards, Eiso.
--
_________
_______________________________/ Eiso AB \_________________________
More information about the Gcc-bugs
mailing list