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: <1991Jun7.011938.11342@wdl1.wdl.loral.com> Date: 7 Jun 91 01:19:38 GMT References: <1991Jun4.233928.5185@athena.mit.edu> <1991Jun5.014758.10616@wdl1.wdl.loral.com> <20273@crdgw1.crd.ge.com> Sender: bard@cutter (J H Woodyatt) Distribution: usa Organization: Space Systems/Loral Lines: 61 In article <20273@crdgw1.crd.ge.com>, volpe@camelback.crd.ge.com (Christopher R Volpe) writes: |> In article <1991Jun5.014758.10616@wdl1.wdl.loral.com>, |> bard@cutter.ssd.loral.com (J H Woodyatt) writes: |> |>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. |> |>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.) |> |> Yes, it is undefined according to ANSI. It has nothing to do with order |> of evaluation, though. You are right about the value of each assignment |> expression, but that's not the point. The problem, as Steve pointed out, |> is that the value of "i" is modified twice between sequence points. As |> a result, all bets are off, since the Standard says that this is not allowed |> and that anything can happen if you do it. |> |> -Chris |> |> |>| |> |>| James Woodyatt |> |> ================== |> Chris Volpe |> G.E. Corporate R&D |> volpecr@crd.ge.com <> I might submit to you that all bets are off concerning the value stored in `i' after the expression is evaluated, but as for the result of the expression, if *that* is undefined, then it isn't by any means intuitive. And, by the way, I *have* a copy of the FAQ, and I *have* read it. I am quite aware of the problem of side effects with order of evaluation; I think the side effect in the above expression renders the value of `i' undefined, *not* the result of the expression. I also have a related question. Given the following: extern volatile int k; if (k = 1) /* Yes, this is an assignment, not an equivalence test */ { .... } I would expect that it is undefined whether the block after the `if' expression will be executed. Am I right? __________________________________________________________________ | | 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 |