order of evaluation

utzoo!decvax!harpo!npoiv!npois!houxm!houxa!houxk!houxj!wapd utzoo!decvax!harpo!npoiv!npois!houxm!houxa!houxk!houxj!wapd
Fri Feb 25 13:04:20 AEST 1983


	Recently I came across a C compiler for a certain microprocessor
(never mind which one) that evaluates strange expressions in an order
that I think may be illegal.

	If the program starts with :

		int i ;
		int table[5] ;
		i=0 ;

	What happens if the next line is one of the following ?

		table[i++]=i++ ;
		table[++i]=++i ;
		table[i++]=++i ;
			and so on ...

	Well, what happens is that all pre-increments are done first,
then all expressions are evaluated using the values of variables at
that point, the assignment is performed, and then all post-increments
are performed.

	Does this violate the C standard ?  Doesn't C guarantee that
each expression will be evaluated entirely before another expression
is evaluated ?  I know that C doesn't guarantee the order in which
expressions are evaluated, but isn't each expression indivisibly
evaluated ?

	Something different happens depending on whether the declaration
is "int i ;" or "register int i ;", but I don't want to think about
that one.

					Bill Dietrich
					houxj!wapd

PS:  I wouldn't be caught dead writing code like that.



More information about the Comp.lang.c mailing list