This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

5*1.2 = 5 or 5*1.2 = 6 ?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]