Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!wdl1!cutter!bard From: bard@cutter.ssd.loral.com (J H Woodyatt) Newsgroups: comp.lang.c Subject: Re: Evaluation of if's Message-ID: <1991Jun5.014758.10616@wdl1.wdl.loral.com> Date: 5 Jun 91 01:47:58 GMT References: <1991Jun4.233928.5185@athena.mit.edu> Sender: bard@cutter (J H Woodyatt) Distribution: usa Organization: Space Systems/Loral Lines: 35 In article <1991Jun4.233928.5185@athena.mit.edu>, scs@adam.mit.edu (Steve Summit) writes: |> In article fpb@ittc.wec.com (Frank P. Bresz) writes: |> > if ( (i=1) == (i=2) ) |> > |> >Is somebody wrong or is the behavior undefined? |> >Personal opinion: I think the behaviour is undefined by K&R anyway I can't |> >say for ANSI. |> |> Of course it's undefined. (It contains two side effects not |> separated by a sequence point.) Is this really undefined by ANSI? I suppose we need someone with the STANDARD to resolve this. (I'm politely assuming that there is a good reason for wanting to though I'm unable to think of one.) My 2nd edition K&R book says in the glossary (p.208) that the result of an assignment expression is the value that was stored in the lvalue after the assignment takes place. Thus, independent of order of evaluation, the above expression should always evaluate FALSE. (Or at least so say I.) The fact that *my* compiler seems to overlook this wording is somewhat alarming to me. I'd like to know what *else* it's willing to ignore, mangle or optimize into oblivion incorrectly. Which leads to an interesting question about portable programming. What fringy kinds of things in a standard can one expect compilers to sometimes overlook and thus be classifiable in the category of `Bad Programming Practice.' __________________________________________________________________ | | James Woodyatt VOICE: (415) 852-5429 | Space Systems/Loral (M/S G87) FAX: (415) 852-6286 | 3825 Fabian Way E-MAIL: bard@cutter.ssd.loral.com | Palo Alto, CA 9430 |