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]
Other format: [Raw text]

Problems with g++ -O2 (v. 3.1, a bug?)


Hello there,
this tiny program test.c produces different output compiled with
gcc 3.1 on my athlon-linux-2.4.10

// Program start
#include <stdio.h>

struct S {
  int i1;
  int i2;
};

inline struct S Sdiff( struct S start, struct S stop ) {
   struct S myS = { stop.i1 - start.i1, stop.i2 - start.i2 };
   return myS;
}

int main()
{
   struct S a = {1,1};
   struct S b = {2,2};
   struct S c = Sdiff(a,b);
   printf( "c: %d %d\n",c.i1, c.i2);
}
// Program end

compiled with
   g++ -O2 test.c   -o test
   -> "c: 134518664 0"
and
   g++ -O0 test.c   -o test
   -> "c: 1 1" (as it supposed to be)

compiled with cc the output is correct in either
case, with or without optimization.

Can anyone reproduce this problem, is this a bug?

Birger





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