order of evaluation parse date s - (nf)

utzoo!watmath!watcgl!dmmartindale utzoo!watmath!watcgl!dmmartindale
Wed Mar 9 00:22:41 AEST 1983


It isn't necessarily true that i == 5 after executing i = 4; i = i++;
Consider the following code sequence for i=i++ on a hypothetical machine:

	lda	i	# load i into accumulator
	aos	i	# do post-increment with Add One to Storage instruction
	sta	i	# and then store back into i

At the end, i == 4.
This is a perfectly reasonable code sequence to generate on a machine
that has no two-operand instructions, but does have an "aos" instruction.
Moral: Never try to second-guess the compiler and hardware when the result
is not defined by the semantics of the language.

	Dave Martindale



More information about the Comp.lang.c mailing list