This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
5*1.2 = 5 or 5*1.2 = 6 ?
- From: "Jocelyn Fournier" <joc at presence-pc dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Tue, 16 Jul 2002 12:16:49 +0200
- Subject: 5*1.2 = 5 or 5*1.2 = 6 ?
- Organization: Presence-PC
- Reply-to: "Jocelyn Fournier" <joc at presence-pc dot com>
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