On Tue, 13 Apr 2010 15:59:24 +1000, Anthony Towns <a...@erisian.com.au> wrote: > On Tue, Apr 13, 2010 at 14:10, Dirk Hohndel <hohn...@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 _______________________________________________ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch