Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 79FD24196F2 for ; Tue, 13 Apr 2010 05:42:43 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -4.2 X-Spam-Level: X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QxpcbWDM2ql2 for ; Tue, 13 Apr 2010 05:42:41 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by olra.theworths.org (Postfix) with ESMTP id 704B8431FC1 for ; Tue, 13 Apr 2010 05:42:41 -0700 (PDT) Received: from localhost ([::1] helo=x200.gr8dns.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1O1fRw-0000qd-Hq; Tue, 13 Apr 2010 12:42:40 +0000 Received: by x200.gr8dns.org (Postfix, from userid 500) id 053BCC00E1; Tue, 13 Apr 2010 05:42:39 -0700 (PDT) From: Dirk Hohndel To: Anthony Towns Subject: Re: [PATCH] Add simplistic reimplementation of strcasestr to compat library In-Reply-To: References: Date: Tue, 13 Apr 2010 05:42:39 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2010 12:42:43 -0000 On Tue, 13 Apr 2010 15:59:24 +1000, Anthony Towns wrote: > On Tue, Apr 13, 2010 at 14:10, Dirk Hohndel wrote: > > +/* the semantic here actually puzzles me: > > + =C2=A0 how can haystack be const char * - yet the return value is cha= r * > > + =C2=A0 after all, it points to a sub-string of haystack... */ >=20 > 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: >=20 > char *strcasestr(char *haystack, const char *needle); >=20 > for when you're doing a search and replace on the needle (say), and: >=20 > const char *strcasestr(const char *haystack, const char *needle); >=20 > 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 --=20 Dirk Hohndel Intel Open Source Technology Center