Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: still problems with ?: Message-ID: <568@lakart.UUCP> Date: 12 Jun 89 14:03:54 GMT References: <10387@smoke.BRL.MIL> Organization: Lakart Corporation, Newton, MA Lines: 29 gwyn@smoke.BRL.MIL (Doug Gwyn) sez: > In article <4675@alvin.mcnc.org> spl@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@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+