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


Groups > comp.lang.c > #101449

Re: standard error codes

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: standard error codes
Date 2017-01-11 12:03 -0800
Organization None to speak of
Message-ID <lnmvexpdoq.fsf@kst-u.example.com> (permalink)
References (13 earlier) <o5387t$vp5$1@dont-email.me> <ln7f62r7xp.fsf@kst-u.example.com> <e1efc303-fba2-4536-ba9e-e69fc3edffb1@googlegroups.com> <o55t89$k2e$1@dont-email.me> <o55vqs$u6v$1@dont-email.me>

Show all headers | View raw


BartC <bc@freeuk.com> writes:
> On 11/01/2017 18:25, Richard Heathfield wrote:
[...]
>> Yes, I'd agree with that. We don't need a streq function. What's wrong
>> with strcmp?
>
> Because 99% of all calls to strcmp use it to compare for string equality?

And why is that a problem?

In the early days, it turned out to be just as easy to provide
a string comparison function as a slightly less flexible string
equality function.  It ain't broke.  Why fix it?

> I've looked at some codebases and the overwhelming use of strcmp seems 
> to either use strcmp(s,t)==0, or !strcmp(s,t). Neither looks obviously 
> like a test for equality.

They certainly do to any C programmer who's familiar with what strcmp()
does.

> In one or two places, I saw a call like this: if (strcmp(s,t)), which is 
> even less intuitive (I think it tests whether s is not equal to t).

Yes, that's what it does (you're not sure?).  I wouldn't write
it that way myself, but it's perfectly understandable *if* you
understand what strcmp() does.

> With streq, those first calls would look like this:
>
>     if (streq(s,t))
>
> and the second like this:
>
>     if ( !streq(s,t))
>
> In theory, because could create a streq-like function using macros or a 
> wrapper, but someone neglected to tell the people who wrote this code!

Apparently the people who wrote the code didn't feel the need to write a
streq() macro, because they felt, as I do, that calling strcmp()
directly is clear enough.  You seem to be assuming that, if the authors
of the code you're looking at *had only known* that they could wrap
strcmp() in a macro, then of course they would have done so to
make their code clearer.  I disagree.

(BTW, the name "streq" is reserved.  If I felt the need for such a
macro, I might call it "STREQ".)

> It doesn't happen.

Not often, but it can happen in your code if you want it to.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

standard  error codes Thiago Adams <thiago.adams@gmail.com> - 2017-01-08 06:34 -0800
  Re: standard  error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-08 11:05 -0800
    Re: standard  error codes Thiago Adams <thiago.adams@gmail.com> - 2017-01-09 03:33 -0800
      Re: standard  error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-09 04:55 -0800
        Re: standard  error codes Keith Thompson <kst-u@mib.org> - 2017-01-09 09:06 -0800
          Re: standard  error codes Thiago Adams <thiago.adams@gmail.com> - 2017-01-09 09:52 -0800
            Re: standard error codes BartC <bc@freeuk.com> - 2017-01-09 21:50 +0000
              Re: standard error codes BartC <bc@freeuk.com> - 2017-01-09 22:36 +0000
                Re: standard error codes supercat@casperkitty.com - 2017-01-09 14:51 -0800
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-09 23:39 +0000
                Re: standard error codes supercat@casperkitty.com - 2017-01-09 15:51 -0800
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-09 16:08 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-09 18:51 -0800
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 02:02 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-10 07:34 -0800
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-10 01:39 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-10 09:07 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-10 09:59 -0800
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-10 12:02 -0800
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 12:53 -0800
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-10 13:03 -0800
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 15:41 -0800
                Re: standard error codes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-11 02:56 +0000
                Re: standard error codes supercat@casperkitty.com - 2017-01-11 07:42 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-10 12:59 -0800
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-10 18:14 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-10 12:12 -0800
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-10 20:35 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-10 13:00 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-11 08:16 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 18:25 +0000
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-11 19:09 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-11 12:03 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 20:10 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-11 12:19 -0800
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-11 20:31 +0000
                Re: standard error codes Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-01-11 15:32 -0500
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 20:48 +0000
                Re: standard error codes Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-01-11 15:58 -0500
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-11 13:01 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 21:05 +0000
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-11 21:08 +0000
                Re: standard error codes Gareth Owen <gwowen@gmail.com> - 2017-01-11 21:38 +0000
                Re: standard error codes BartC <bc@freeuk.com> - 2017-01-11 21:58 +0000
                Re: standard error codes David Brown <david.brown@hesbynett.no> - 2017-01-12 12:11 +0100
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-12 09:28 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-12 18:06 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-12 11:39 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-12 19:50 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-12 13:03 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-12 21:13 +0000
                Re: standard error codes <william@wilbur.25thandClement.com> - 2017-01-12 20:00 -0800
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-13 01:56 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-13 12:54 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-13 09:35 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-13 17:38 +0000
                Re: standard error codes James Kuyper <jameskuyper@verizon.net> - 2017-01-13 13:06 -0500
                Re: standard error codes raltbos@xs4all.nl (Richard Bos) - 2017-01-18 12:00 +0000
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-18 12:13 +0000
                Re: standard error codes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-12 16:43 -0800
                Re: standard error codes <william@wilbur.25thandClement.com> - 2017-01-12 19:34 -0800
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-13 09:27 -0800
                Re: standard error codes raltbos@xs4all.nl (Richard Bos) - 2017-01-12 19:33 +0000
                Re: standard error codes Keith Thompson <kst-u@mib.org> - 2017-01-12 12:10 -0800
                Re: standard error codes supercat@casperkitty.com - 2017-01-11 11:50 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 20:38 +0000
                Re: standard error codes jadill33@gmail.com - 2017-01-11 12:26 -0800
                Re: standard error codes Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 20:44 +0000
      Re: standard  error codes Keith Thompson <kst-u@mib.org> - 2017-01-09 09:03 -0800
  Re: standard  error codes supercat@casperkitty.com - 2017-01-08 11:40 -0800

csiph-web