Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: const * question Message-ID: <6578@brl-smoke.ARPA> Date: Mon, 19-Oct-87 08:31:13 EDT Article-I.D.: brl-smok.6578 Posted: Mon Oct 19 08:31:13 1987 Date-Received: Tue, 20-Oct-87 02:06:31 EDT References: <1151@lznv.ATT.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 22 Keywords: const pointer In article <1151@lznv.ATT.COM> psc@lznv.ATT.COM (Paul S. R. Chisholm) writes: >char * >next( const char *s ) >{ > const char *p; > p = s + 1; > return p; >} >Here's the rub: my compiler (Turbo C) complains that the return >statement is a suspicious pointer conversion. It IS "suspicious", but not necessarily erroneous, depending on what s actually pointed to and what you will subsequently do with p. I recommend writing p = (char *)s + 1; to indicate that you know about the constness and are deliberately ignoring it. All that const on a formal function parameter means is that the function itself shall not use that pointer to modify data, not that the data pointed to is necessarily non-modifiable. This is a subtle but important distinction.