++ operator

Mark Plotnick mp at mit-eddie.UUCP
Mon Dec 26 08:30:47 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.

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 reference manual is vague here, but a good rule of thumb is that
foo++ is equivalent to ((foo=foo+1)-1).  I don't know of any exceptions
to this off-hand, although I heard that a pcc author was once thinking of
delaying the postincrement of function args until after the function call
[i.e. f(i++) would be equivalent to (temp=f(i),i++,temp) ].

Since there are still quite a few C compilers being written from
scratch out there, it would really help if someone were to come up with
a precise, consistent definition for how the postincrement and
postdecrement operators should behave.  Ditto for enum, void,
unsigned chars, non-integer bitfields, etc.

	Mark



More information about the Comp.lang.c mailing list