From: Dirk Hohndel <hohndel@infradead.org>
To: Anthony Towns <aj@erisian.com.au>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH] Add simplistic reimplementation of strcasestr to compat library
Date: Tue, 13 Apr 2010 05:42:39 -0700 [thread overview]
Message-ID: <m38w8rcym8.fsf@x200.gr8dns.org> (raw)
In-Reply-To: <h2r87b3a4191004122259ofc26c84dk7ebc53c250ffb263@mail.gmail.com>
On Tue, 13 Apr 2010 15:59:24 +1000, Anthony Towns <aj@erisian.com.au> wrote:
> On Tue, Apr 13, 2010 at 14:10, Dirk Hohndel <hohndel@infradead.org> wrote:
> > +/* the semantic here actually puzzles me:
> > + how can haystack be const char * - yet the return value is char *
> > + after all, it points to a sub-string of haystack... */
>
> Dunno if this is a question from the original source, but the answer
No, that was me being puzzled :-)
> if anyone's interested is probably because C doesn't have templates --
> you'd ideally like to have it treated as:
>
> char *strcasestr(char *haystack, const char *needle);
>
> for when you're doing a search and replace on the needle (say), and:
>
> const char *strcasestr(const char *haystack, const char *needle);
>
> for when you're doing a search for the needle in something you can't
> modify. But C isn't clever enough to let you say that with just one
> function (and no fancy #defines), so you have to drop some of the
> typechecking with the (char*) cast on the return value if you want to
> handle both use cases, without the compiler complaining about
> const->non-const conversions in otherwise correct code in one case or
> the other.
That makes sense. Thanks
/D
--
Dirk Hohndel
Intel Open Source Technology Center
prev parent reply other threads:[~2010-04-13 12:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-13 4:10 [PATCH] Add simplistic reimplementation of strcasestr to compat library Dirk Hohndel
2010-04-13 4:20 ` Tomas Carnecky
2010-04-13 5:59 ` Anthony Towns
2010-04-13 12:42 ` Dirk Hohndel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m38w8rcym8.fsf@x200.gr8dns.org \
--to=hohndel@infradead.org \
--cc=aj@erisian.com.au \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).