Path: utzoo!attcan!telly!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uunet!shelby!agate!ucbvax!VM.UOGUELPH.CA!SOFPJF From: SOFPJF@VM.UOGUELPH.CA (Peter Jaspers-Fayer) Newsgroups: comp.sys.sgi Subject: Mixed mode Arithmatic Message-ID: <9102211136.aa10474@VGR.BRL.MIL> Date: 21 Feb 91 15:44:18 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: Computing Services, University of Guelph, Ont. Can. N1G 2W1 Lines: 51 Seems that SGI C is different from any other C that we've seen when it comes to adding pointers and long ints in various combinations. #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 */ } Sequent and others: Sizes: a P 4 4 s,P: 1073735252 1073735252 a,b: 2 5 a+P+b: 1073735280 a+b+P: 1073735280 a+(P+b): 1073735280 a+(b+P): 1073735280 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 [!] 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 may be surprised at how litterally SGI's C takes these sort of expressions. In every other compiler, I would guess that the ints are added together first, then the result used to bump the pointer, regardless of the order or punctuation of the expression. /PJ SofPJF@VM.UoGuelph.Ca -------------------------------------- An ounce of application is worth a ton of abstraction. Brought to you by Super Global Mega Corp .com