🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #108

Bugreport for gcc v1.35

#108
From: Anders Christensen
Date: Mon, 19 Jun 1989 00:54
35 lines
1732 bytes
I think I have come over a bug in gcc. The following program seems to
produce code which executes incorrectly.

#include <stdio.h>
main()
{
  int i=0, j=10, k=100, l ;
  k += ((i=0) ? (j--) : 0) ;        /* incorrectly executed statement */
  printf("j should be 10, but seems to be %d\n", j ) ;  /* writes '9' */
  exit(0) ;
}

What happens is that the expression ((i=0) ? (j--) : 0) decrements
the variable 'j'. I believe that the (j--) part of the statement never
should be evaluated. The program will execute correctly (i.e. the 
variable 'j' will continue to have the value 10) if I substitute the
offending line with any of these:

  k  = ((i=0) ? (j--) : 0)     ;
  k += (  0   ? (j--) : 0)     ;
  k += ((i=0) ? (j--) : (l=0)) ;
  
I have tested it on the following machines, and observed the bug. I have
used no special options on the command line ( gcc -o test test.c )

  - gcc v1.34 on a Sun 3/60 running SunOS v4.0.1
  - gcc v1.35 on a Sun 3/280 running SunOS v3.5
  - gcc v1.35 on a VAX 11/780 running Ultrix v2.2

I hope this will help you to find and remove this bug. I will also like
to thank you for a *great* compiler, which is far better than most 
commercially available software.

Anders Christensen  ( achriste@norunit.bitnet,  anders@idt.unit.no )
Norwegian Institute of Technology, Trondheim
Technical Details
Message-ID: <13155.8906190054@loke.idt.unit.no>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!idt.unit.no!anders

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!idt.unit.no!anders
From: anders@idt.unit.no (Anders Christensen)
Newsgroups: gnu.gcc.bug
Subject: Bugreport for gcc v1.35
Message-ID: <13155.8906190054@loke.idt.unit.no>
Date: 19 Jun 89 00:54:07 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 35