still problems with ?:

David Goodenough dg at lakart.UUCP
Tue Jun 13 00:03:54 AEST 1989


gwyn at smoke.BRL.MIL (Doug Gwyn) sez:
> In article <4675 at alvin.mcnc.org> spl at mcnc.org.UUCP (Steve Lamont) writes:
>>>((a = *p++) && e2 ) || (!a && e3)
>>Is right to left evaluation mandated in this case?  It seems to me that
>>I've been bitten by things like this before, either by non-standards
>>conforming compilers, ambiguous definition in the standard, my own
>>stupidity, or all of the above.  In any case, it seems that defensive
>>programming might dictate something like ...
> 
> There has never been any ambiguity about the correct sequence of
> operations during evaluation of such an expression (except when
> `p' is used in `e2' or `e3').

Huh??? - if I use p in e2 or e3, my compiler had better use the value
_AFTER_ the *p++, otherwise I'm going to ask for my money back. In the
above code fragment if _ANYTHING_ is executed before the a = *p++ then
the compiler is broken. The same applies to:

	if ((a = *p++) ? e2 : e3)

The a = *p++ part has to be done first so that the compiler knows which
of e2 and e3 to do. Of course if your going to tell me that the standard
says that the a = *p and the p++ may happen at different times (i.e. the
p++ after e2), then I'm going to say the standard is broken.
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.lang.c mailing list