This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC Bug
- To: gcc-bugs at gcc dot gnu dot org
- Subject: GCC Bug
- From: Jonathan Blogh <jsb97r at ecs dot soton dot ac dot uk>
- Date: Wed, 09 Aug 2000 15:27:21 +0100
Hello
This short piece of code produces the wrong output when compiled with
GCC 2.95.2-12/13 with the -O2 option, however it works fine with -O1. No
other compilation options were used. This occurred under Debian Linux
(various kernel versions).
The problem is that wn[8] does not get set to 9.0 when O2 is used.
However, if the (double)(i+1) is changed to (double)(i+1.0) it works or
(double)(i)+1.0 it works too!
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
int main(void)
{
double wn[11];
int i;
for(i=0;i<9;i++) {
/* printf("i=%d\n", i); */
wn[i]=(double)(i+1);
}
wn[i]=2.0;
for(i=0;i<10;i++) {
printf("wn[%d]=%f\n", i, wn[i]);
}
return(0);
}
I hope this is of some use.
Jonathan Blogh