From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1051a8,c93bbac4dc8636ac,start X-Google-Attributes: gid1051a8,public X-Google-Thread: 1164f8,c93bbac4dc8636ac,start X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1990-02-01 01:49:39 PST Path: gmdzi!unido!mcsun!uunet!samsung!usc!ucsd!helios.ee.lbl.gov!pasteur!modoc.berkeley.edu!jac From: jac@modoc.berkeley.edu (Gordon Jacobs) Newsgroups: comp.sys.dec,comp.sys.mips Subject: BUG is MIPS cc for "?" operator Keywords: compiler, MIPS Message-ID: <21624@pasteur.Berkeley.EDU> Date: 31 Jan 90 21:48:14 GMT Sender: news@pasteur.Berkeley.EDU Reply-To: jac@modoc.berkeley.edu (Gordon Jacobs) Organization: University of California, Berkeley Xref: gmdzi comp.sys.dec:1927 comp.sys.mips:317 Posted: Wed Jan 31 22:48:14 1990 The program below demonstrates various uses of the "?" selection operator in c that seem to not work correctly on a DEC3100 running Ultrix3.1. This has also been compiled on a unit running a test version of Ultrix4.0 with the exact same results. This seems like a fairly major bug and it could affect much old software. Has anyone experienced this or confirmed it?? The test program shows version which work and don't work... Thanks, Gordie Jacobs, UCB ------------------ cut here -------------------------------------- #define MAX(A,B) ((A)>(B))?(A):(B) #define BITS_PER_INT (sizeof(int)*8) #define INTS_PER_BUS ((int)(20/BITS_PER_INT)+1) main () { int high, low; int bits_per_int, sizeofint; printf("INTS_PER_BUS=%d BITS_PER_INT=%d\n", INTS_PER_BUS, BITS_PER_INT); bits_per_int= BITS_PER_INT; sizeofint= sizeof(int); high= 19; /* All of these compute the wrong answer (-12 instead of 0) */ low = MAX(0, high-BITS_PER_INT+1); low = (0>(high-BITS_PER_INT+1))?(0):(high-BITS_PER_INT+1); low = MAX(0, high-sizeof(int)*8+1); low = (0>(high-sizeof(int)*8+1))?(0):(high-sizeof(int)*8+1); /* Works: #define BITS_PER_INT 32 low = MAX(0, high-BITS_PER_INT+1); */ /* Works: low = MAX(0, high-sizeofint*8+1); */ /* Works: low = MAX(0, low=high-BITS_PER_INT+1); */ /* Works: low = (0>(high-bits_per_int+1))?(0):(high-bits_per_int+1); */ /* Works: low = (0>(high-32+1))?(0):(high-32+1); */ /* Works: low = high-BITS_PER_INT+1; low = MAX(0,low); */ printf("high=%d low=%d MAX(0,-12)=%d\n", high, low, MAX(0,-12)); }