Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #21437

Re: Open letter to Ian Collins

Message-ID <4FC2A153.78AA@mindspring.com> (permalink)
Date 2012-05-27 17:49 -0400
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: Open letter to Ian Collins
References (6 earlier) <lny5odisrc.fsf@nuthaus.mib.org> <4FC26A8F.5DEB@mindspring.com> <jpu2h5$16r$1@speranza.aioe.org> <jpu57n$72n$1@dont-email.me> <lntxz1ia1w.fsf@nuthaus.mib.org>

Show all headers | View raw


Keith Thompson wrote:
> 
> "BartC" <bc@freeuk.com> writes:
> > "jacob navia" <jacob@spamsink.net> 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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 00:22 +0200
  Re: Open letter to Ian Collins Ike Naar <ike@sverige.freeshell.org> - 2012-05-26 22:36 +0000
    Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 01:13 +0200
      Re: Open letter to Ian Collins Barry Schwarz <schwarzb@dqel.com> - 2012-05-26 16:53 -0700
    Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-26 16:41 -0700
      Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-26 22:43 -0400
  Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-26 15:41 -0700
    Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 01:14 +0200
  Re: Open letter to Ian Collins MelissA <melis@a.com> - 2012-05-27 00:52 +0200
  Re: Open letter to Ian Collins Stephen Sprunk <stephen@sprunk.org> - 2012-05-26 20:40 -0500
    Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:32 +0200
      Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 07:18 -0400
  Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 14:24 +1200
    Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 10:36 +0100
      Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 22:33 +1200
        Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 12:25 +0100
          Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-28 07:17 +1200
      Re: Open letter to Ian Collins Ike Naar <ike@sverige.freeshell.org> - 2012-05-27 13:03 +0000
  Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 15:16 +1200
    Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:30 +0200
      Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 20:56 +1200
        Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 11:12 +0200
          Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 21:22 +1200
            Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 07:15 -0400
            Re: Open letter to Ian Collins Keith Thompson <kst-u@mib.org> - 2012-05-27 07:49 -0700
              Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 13:55 -0400
                Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 22:24 +0200
                Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 22:09 +0100
                Re: Open letter to Ian Collins Keith Thompson <kst-u@mib.org> - 2012-05-27 14:33 -0700
                Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 17:49 -0400
                Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 17:31 -0400
                Re: Open letter to Ian Collins Philip Lantz <prl@canterey.us> - 2012-05-28 01:38 -0700
                Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-28 08:18 -0400
        Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 15:46 +0100
        Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-13 21:25 -0400
          Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-13 21:52 -0400
          Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-06-14 04:00 +0200
            Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-14 00:04 -0400
  Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:42 +0200
  Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-28 12:39 +0200
    Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-28 21:44 +0200
      Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-29 09:46 +0200
        Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:06 +0200
          Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:37 +0200
            Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:58 +0200
              Re: Open letter to Ian Collins "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-05-29 11:34 +0200
              Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-29 03:02 -0700
      Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 09:59 +0200
      Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 20:09 +0200
  Re: Open letter to Ian Collins "Sarah Wren" <swreb@ameritech.net> - 2012-05-29 01:40 -0600

csiph-web