5*1.2 = 5 or 5*1.2 = 6 ?
Jocelyn Fournier
joc@presence-pc.com
Tue Jul 16 03:16:00 GMT 2002
Hi,
I've just tested the following simple code :
#include <stdio.h>
main()
{
int x = 5;
x *= 1.2;
printf("5 x 1.2 = %d\n", x);
}
I've compiled it with gcc 3.1
First try :
gcc -o code1 code1.c
[root@forum] /home/joce> ./code1
5 x 1.2 = 5
Second try :
gcc -O -o code1 code1.c
[root@forum] /home/joce> ./code1
5 x 1.2 = 6
Why does the compiler return a different result if the -O is used ?
Thanks in advance,
Regards,
Jocelyn Fournier
More information about the Gcc-help
mailing list