still problems with ?:

Steve Lamont spl at mcnc.org
Sat Jun 10 05:07:09 AEST 1989


In article <10387 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>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
>> [my paranoia deleted to save embarrassment]
>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').  The outermost operator is ||; to
>evaluate ex1||ex2 the compiler is obliged to generate code that

Right.  The FM (K&R, First Edition, p. 19) sez:

"Expressions connected by && or || are evaluated from left to right, and
it is guaranteed that evaluation will stop as soon as truth or falsehood
is known."

I should've looked before posting.  The thing I like about this group is
the sense of humility it brings to me!

>existing C source code.  I don't think you really need to guard
>against totally broken compilers; if you start worrying about that,
>there is no end to the things that "might" be done wrong..

Don't know if I exactly agree with that.  I've *had* to use some fairly
broken compilers... :-)
-- 
							spl
Steve Lamont, sciViGuy			EMail:	spl at ncsc.org
North Carolina Supercomputing Center	Phone: (919) 248-1120
Box 12732/RTP, NC 27709



More information about the Comp.lang.c mailing list