This is the mail archive of the gcc-bugs@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]

GCC Bug


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



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