Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!pyrdc!grebyn!ckp From: ckp@grebyn.com (Checkpoint Technologies) Newsgroups: comp.lang.c Subject: Re: Evaluation of if's Message-ID: <1991Jun5.123931.22105@grebyn.com> Date: 5 Jun 91 12:39:31 GMT References: <1991Jun4.233928.5185@athena.mit.edu> Distribution: usa Organization: Grebyn Timesharing Lines: 27 In article <1991Jun4.233928.5185@athena.mit.edu> scs@adam.mit.edu 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.) You know, that was my first impression. But after thinking about it, I'm not so sure. You see, I think the (i=1) should evaluate to the value 1, and the (i=2) should evaluate to the value 2, regardless of the order in which they're performed. The order of operations will give the resulting value for i after the if statement. The variable i is not fetched during the entire statement, so the order in which the variable is stored should not matter. Unless someone thinks the compiler should evaluate (i = 1) by storing 1 in i, then fetch that value back some time later for the comparison, but I seem to recall some ANSI rules about how many times a storage object may be touched between sequence points. -- Richard Krehbiel, private citizen ckp@grebyn.com (Who needs a fancy .signature?)