Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!tdatirv!sarima From: sarima@tdatirv.UUCP (Stanley Friesen) Newsgroups: comp.lang.c Subject: Re: a style question Message-ID: <9@tdatirv.UUCP> Date: 5 Oct 90 23:14:25 GMT References: <1990Oct2.151644.1581@phri.nyu.edu> <1275.270afcdb@iccgcc.decnet.ab.com> Reply-To: sarima@tdatirv.UUCP (Stanley Friesen) Organization: Teradata Corp., Irvine Lines: 27 In article <1275.270afcdb@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes: >davis@pacific.mps.ohio-state.edu (John E. Davis) writes: >> Which ['x != 100' or 'x < 100' RHS] generates faster code? >When hesitating between two styles, I believe that _in general_ these >questions are the ones to ask, in descending order of priority: > > 1. Which is correct? ... > 2. Which is clearer? ... > 3. Which is faster? I think you missed an important question: 1.5 Which is more robust? - that is which form is less likely to lead to a bug being introduced later? This is *not* the same as question #1, since both can be correct *now* and still differ as to roubustness. In this particular case this is the situation. 'x != 100' used in a loop (as the original question asked) is *dangerous*. If the loop should happen to increment x somehere other than the loop control, the resulting loop will likely be infinite! The 'x < 100' form guarentees that no matter how the loop is modified later it will terminate correctly, rather than hang the program (or worse). Have pity on the maintainer and use the robust form! -- --------------- uunet!tdatirv!sarima (Stanley Friesen)