Fun and games with ++ operators

Phil Ronzone pkr at sgi.com
Sat Sep 29 08:34:17 AEST 1990


In article <9009211425.AA04291 at snowhite.cis.uoguelph.ca> mike at SNOWHITE.CIS.UOGUELPH.CA writes:
>			printf("%d %d\n", a[i++], a[i++]);
>    Depending on the order of evaluation of function arguments, I would expect
>this code to generate "6 5" or "5 6".  But instead it says "5 5", which 
>confuses me a bit.  Do all pre/post increment/decrement operators only
>take effect after the current source line, or what?  I did check the value
>of 'i' on the next line, and it was indeed 2, so that part works.


Such behaviour is ill-defined and I thought that K&R had an explicit warning
about it. I.e., don't do that kind of stuff, especially in passing arguments!


--
<---------------------------------------------------------------------------->
Philip K. Ronzone                  S e c u r e   U N I X           pkr at sgi.com
Silicon Graphics, Inc. MS 9U-500                           work (415) 335-1511
2011 N. Shoreline Blvd., Mountain View, CA 94039            fax (415) 969-2314



More information about the Comp.sys.sgi mailing list