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

optimization problem with 1.0.3



I'm not sure what to make of this problem.  This simple program
behaves differently when compiled with or without optimization.

The problem seems to go away when any of the following happens:
	1.  The needless 'for' loop is taken out
	2.  The 'for' loop is replaced with a do {} while(0);
	3.  Both occurrences of 3.0 are replaced with 2.0

I am working on Intel/Linux.

--------------

beefalo% cat egcs_problem_p.c 
#include <stdio.h>

int main()
{
  int count;
  double x = 1.0;
  
  for(count=0;count<1;count++) {
    x = x/3.0;
    if(x != 1.0/3.0)
      printf("That's odd...\n");
  }
  return 0;
}
beefalo% gcc egcs_problem_p.c 
beefalo% a.out 
beefalo% gcc -g0 -O egcs_problem_p.c
beefalo% a.out
That's odd...
beefalo% gcc -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)


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