Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!MCC.COM!nong From: nong@MCC.COM Newsgroups: comp.sys.sgi Subject: Re: Fun and games with ++ operators Message-ID: <9009211942.AA07458@banach.aca.mcc.com> Date: 21 Sep 90 19:42:32 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: nong@mcc.com Organization: The Internet Lines: 31 > #include > int a [2]; > main() > { > int i; > a[0] = 5; > a[1] = 6; > i = 0; > printf("%d %d\n", a[i++], a[i++]); > } ..... >..... I only have the ancient K&R, which as far as I can tell does not > formally specify when these operators are supposed to do their thing. For > reference purposes, I ran this code on many platforms (6 different CPUs, > 8 different compilers), and only the MIPS compiler came out with the "5 5" > answer. According to K&R ( p 59 1st edition, or 63 2nd edition ) " The commas that separate function arguments, variables in declarations, etc., are not comma operators, and do not guarantee left to right evaluation." In this case the arguments may be evaluated in parallel. It'll be interesting to see if i is printed as the last variable in the same print statment, will it be 0. ______________ Nong Tarlton Microelectonics and Computer Technology Corporation nong@mcc.com