Mixed mode Arithmatic

David B.Anderson davea at quasar.wpd.sgi.com
Fri Feb 22 12:03:52 AEST 1991


In article <9102211136.aa10474 at VGR.BRL.MIL>, SOFPJF at VM.UOGUELPH.CA (Peter Jaspers-Fayer) writes:
[stuff deleted]
> #include <stdio.h>
> 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 at sgi.com ]
[``What can go wrong?''                           --Calvin to Hobbes]



More information about the Comp.sys.sgi mailing list