Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!sgi!davea@quasar.wpd.sgi.com From: davea@quasar.wpd.sgi.com (David B.Anderson) Newsgroups: comp.sys.sgi Subject: Re: Mixed mode Arithmatic Summary: It is a compiler bug. . Message-ID: <86746@sgi.sgi.com> Date: 22 Feb 91 01:03:52 GMT References: <9102211136.aa10474@VGR.BRL.MIL> Sender: guest@sgi.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 43 In article <9102211136.aa10474@VGR.BRL.MIL>, SOFPJF@VM.UOGUELPH.CA (Peter Jaspers-Fayer) writes: [stuff deleted] > #include > main(){ > long a, b, *P; > char s[2000]; > a = 2; > b = 5; > P = (long*)s; > printf("Sizes: a P %d %d\n",sizeof(a),sizeof(P)); > printf("s,P: %ld %ld\n", s,P); > printf("a,b: %ld %ld\n", a,b); > printf("a+P+b: %ld\n", a+P+b); > printf("a+b+P: %ld\n", a+b+P); > printf("a+(P+b): %ld\n", a+(P+b)); > printf("a+(b+P): %ld\n", a+(b+P)); /* Watch this one */ The compiler generates incorrect code for this. > } [stuff deleted ] > > SGI PI: > Sizes: a P 4 4 > s,P: 2147467180 2147467180 > a,b: 2 5 > a+P+b: 2147467208 > a+b+P: 2147467208 > a+(P+b): 2147467208 > a+(b+P): 2147467292 [!] This last answer is wrong. > As there does not appear to be a fixed standard, I can't say who's > "right", but this note will (I hope) serve as a warning to others that This is simply a bug. The (previously unknown) bug has been around a long time. I have a fix and it will be in the next release (4.0). Thanks to Peter Jaspers-Fayer for providing a nice test case with the bug report. Apologies for any inconvenience..... [ David B. Anderson Silicon Graphics (415)335-1548 davea@sgi.com ] [``What can go wrong?'' --Calvin to Hobbes] Brought to you by Super Global Mega Corp .com