GCC Bug

Jonathan Blogh jsb97r@ecs.soton.ac.uk
Wed Aug 9 07:27:00 GMT 2000


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




More information about the Gcc-bugs mailing list