From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 43BB44196F2 for ; Mon, 12 Apr 2010 22:59:27 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.499 X-Spam-Level: X-Spam-Status: No, score=-0.499 tagged_above=-999 required=5 tests=[BAYES_05=-0.5, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001] 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 G5FnqAvteGCy for ; Mon, 12 Apr 2010 22:59:25 -0700 (PDT) Received: from mail-gy0-f181.google.com (mail-gy0-f181.google.com [209.85.160.181]) by olra.theworths.org (Postfix) with ESMTP id E3C93431FC1 for ; Mon, 12 Apr 2010 22:59:24 -0700 (PDT) Received: by gyg8 with SMTP id 8so3474792gyg.26 for ; Mon, 12 Apr 2010 22:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:received:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=yeDmNraJ1Aun117bESXzfJuWAHHj27OybHs/CJypg8U=; b=To0GQ/ZtzLhSw4uVJCzen/wc3JkKuh7ITGCs/eXTPxPDkL2jS8HZWtIZQ4FxU9U7dd fWPbwv2l3E/U+ZRRO02OznxxAl4186pacGAtKj7iRLbiIPCbgyZj82PFDDIQUvLCROzy emF9T2CmS5L+AKekDTAnWpiDbAxW9RsPSC7jU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=dwwJXVCSbV1h/qhXzh/hJU2ZydO+Blo1uMkTL8yG+lz26Oz+ZSm2LbTbc2XNfMJNVf BjRWDU4Ww1oFxVBoTBQ5Ksd5F5VqdMpzulw3OFETT/vbRe/0qhFnH2tURg/7jKil9JxH viobp/ZNRYHmAMPw+QhU9UfJ3YjieL4upcCho= MIME-Version: 1.0 Sender: anthony.j.towns@gmail.com Received: by 10.90.114.1 with HTTP; Mon, 12 Apr 2010 22:59:24 -0700 (PDT) In-Reply-To: References: Date: Tue, 13 Apr 2010 15:59:24 +1000 X-Google-Sender-Auth: 08b2a26383bfd99d Received: by 10.90.19.22 with SMTP id 22mr2299378ags.67.1271138364341; Mon, 12 Apr 2010 22:59:24 -0700 (PDT) Message-ID: Subject: Re: [PATCH] Add simplistic reimplementation of strcasestr to compat library From: Anthony Towns To: Dirk Hohndel Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 05:59:28 -0000 On Tue, Apr 13, 2010 at 14:10, Dirk Hohndel wrote: > +/* the semantic here actually puzzles me: > + =A0 how can haystack be const char * - yet the return value is char * > + =A0 after all, it points to a sub-string of haystack... */ Dunno if this is a question from the original source, but the answer 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. Cheers, aj --=20 Anthony Towns