operator ?: bug report

Chris Burges burges@lucent.com
Fri Sep 24 09:39:00 GMT 1999


 Hello there -

 I believe the following is a bug in gcc.  I've tried compiling using two
versions: the Linux is on a Pentium II, the solaris is on a Sparc 20.  The
compile command was just "gcc bug.c".

Linux: gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

Solaris: gcc version 2.7.2

The outputs are as follows:
egcs-2.91.66:
1073744168
0 1

gcc version 2.7.2:
20
0 1

Expected output:
1
1 1


Here's the program:


#include <stdio.h>

int main(int argc, char *argv[])
{
  int m = -1;
  int *ptr1 = &m;
  int n[2]={-1, 1};
  int *ptr2 = n;

  /* First example.  ptr1 winds up pointing to unallocated mem, but that should
     not be a problem */
  *ptr1++ = (*ptr1 < 0) ? -(*ptr1) : 20;
  printf("%d\n", m);

  /* Second example */
  *ptr2++ = (*ptr2 < 0) ? -(*ptr2) : 0;
  printf("%d %d\n", n[0], n[1]);
}


 Cheers -
 Chris Burges
 burges@lucent.com


More information about the Gcc-bugs mailing list