Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 27 May 2012 16:49:08 -0500 Message-ID: <4FC2A153.78AA@mindspring.com> Date: Sun, 27 May 2012 17:49:07 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Open letter to Ian Collins References: <4FC26A8F.5DEB@mindspring.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Lines: 48 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.157 X-Trace: sv3-KWvc9eqMcv4np+KaU1r1lroNN6ajyKCo4AyvDaMkpzirngBEYSkanC/1qFsFSNlDPVQJ8RL9Y078mNB!YHoKnLo65AkrH0EQJ8LAcOeVrpmkdBHXJH6zc7OCkTeKKHJMj/7lOEHZdHlL7kviBo5pE/xG8r6m!6FwX5RkTcx4= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2782 Xref: csiph.com comp.lang.c:21437 Keith Thompson wrote: > > "BartC" writes: > > "jacob navia" wrote in message > > news:jpu2h5$16r$1@speranza.aioe.org... > >> Le 27/05/12 19:55, pete a écrit : > >>> I think there's about a zillion combinations of (a) and (b), > >>> where (a - b) has problems. > >> > >> Sure. > >> > >> You want to say then that it is not a good idea in C to write > >> > >> a - b > >> > >> ?? > >> > >> If you think that overflow could be a problem in a comparison you can > >> write something more complicated, expressions can be of any length, it > >> is only important that they be consequent. > > > > Maybe he means there might be more problems using: > > > > (a-b<=0) > > > > than just using: > > > > (a<=b) > > > > for example. Especially when a and b are unsigned. (Assuming the way > > comparisons will be done is along the lines of that former expression.) > > My point is simply that "a - b" is not a reliable way to *compare* > two arbitrary integer values. Using a wider type is not a general > solution. > > If you *don't* think that overflow could be a problem in a > comparison, then you've probably missed something. > > The language doesn't have a built-in 3-way comparison operator, > but it does have < and >. Just use them. My prefered 3-way, to compare 2 integers, is #define COMPAR(A, B) (B > A ? -1 : B != A) -- pete