Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!att!ucbvax!agate!ICSI.Berkeley.EDU!stolcke From: stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) Newsgroups: comp.windows.x Subject: Re: tvtwm patch 5 dumps core Message-ID: <1991May15.192454.27014@agate.berkeley.edu> Date: 15 May 91 19:24:54 GMT References: <1991May11.004433.14527@agate.berkeley.edu> <1991May15.094059.8696@nss1.com> Sender: root@agate.berkeley.edu (Charlie Root) Organization: International Computer Science Institute, Berkeley, CA Lines: 32 In article <1991May15.094059.8696@nss1.com>, mrm@nss1.com (Michael R. Miller) writes: |> In article <1991May11.004433.14527@agate.berkeley.edu> stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) writes: |> >! /* if we haven't received the enter notify yet, wait */ |> >! if (!ActiveMenu || !ActiveMenu->entered) |> > continue; |> |> This is not a correct solution. C compilers are NOT constrained to |> resolve the '||' test in any particular order resulting in the test |> "!ActiveMenu->entered" possibly being accomplished prior to the |> checking of the validity (non-NULLness) of ActiveMenu. This can |> still core dump if compiled under some C compilers. |> |> Presuming the intent of the test is correct, _A_ correct way to |> implement this test is: |> |> if (!(ActiveMenu && ActiveMenu->entered)) |> continue; |> Don't believe it. If your C compiler does not evaluate || strictly left to right (or evaluates the right operand even though the first one is != 0) you better get a new compiler. Look it up in any C reference manual (K+R, ANSI, what have you). That's the whole *point* in having || (and &&) next to | (and &). The alternative solution you proposed makes use of the same principle, mutatis mutandis for the `&&' operator. -- Andreas Stolcke stolcke@icsi.berkeley.edu International Computer Science Institute stolcke@ucbicsi.bitnet 1957 Center St., Suite 600, Berkeley, CA 94704 (415) 642-4274 ext. 126