++ operator

Jim Reuter jreuter at cincy.UUCP
Wed Dec 28 09:30:50 AEST 1983


dave at taurus notes:
	Uh-uh:
		if(*in++ == *in++)

	...

	Also, for those of little faith, there are actually C compilers that
	will take the non-obvious meaning of this (e.g. the PDP-11 cc), and do
	the tests then do both increments in one go after the statement,
	so BE WARNED.
mp at mit-eddie replies:
	I just tried this with the V7 cc, 4.1bsd pcc, and VAX-11 C compilers,
	and in each case two increments were done.

(The implied meaning is that they were done in the proper place.  They
are, I just tested it.)

The real problem here is the ORDER of the increments.  In this example,
order would not matter.  A nice simple example of ordering problems shows
up in the v7 Ritchie compiler:

	int i = 0;

	printf(" %d %d %d %d\n", i++, i++, i++, i++ );

which produces

	3 2 1 0

	Jim Reuter
	(decvax!cincy!jreuter)



More information about the Comp.lang.c mailing list