Path: utzoo!attcan!uunet!tank!mimsy!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.std.c Subject: Re: Thoughts on `const' parameters Message-ID: <9027@smoke.BRL.MIL> Date: 1 Dec 88 18:08:37 GMT References: <957@vsi.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Distribution: comp Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <957@vsi.COM> friedl@vsi.COM (Stephen J. Friedl) writes: > char *strchr(const char *string, int ch) The reason there is a "const" in the first parameter is that it documents the interface requirement that strchr() is not permitted to modify data through that pointer. The reason the result type does NOT have "the const" qualifier is that having it there would prohibit using the returned pointer to modify anything. Whether data is really constant depends on whether it was defined with the const attribute. Pointers to qualified types are representation- compatible with pointers to non-qualified types, so any style of char* can be passed as the first argument to strchr(). >P.S. - did anybody consider putting `index' and `rindex' into the standard? Not for very long. They have been obsolete since 1980, although systems based on obsolete C technology (such as 4BSD) continue to provide them. Use strchr() and strrchr() instead.