Fun and games with ++ operators

Bent Hagemark bh at sgi.com
Sat Sep 29 08:49:37 AEST 1990


In article <1990Sep28.223417.7571 at odin.corp.sgi.com> pkr at sgi.com (Phil Ronzone) writes:
>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

The warning just happens to be on the most important page of K&R C.
For the 2nd edition this is page 53.  I know this because a copy of it
is taped to my office wall right next to my screen!

Bent



More information about the Comp.sys.sgi mailing list