🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #221

Re: const T **

#221
From: John F. Woods
Date: Wed, 15 Apr 1992 15:42
35 lines
1881 bytes
eggert@twinsun.com (Paul Eggert) writes:
>jfw@ksr.com (John F. Woods) writes:
>>it certainly seems to make sense to be able to
>>assign a pointer-to-pointer-to-char into a pointer-to-pointer-to-constant-char.
>Actually, it doesn't make sense to allow such assignments, because if you
>allowed them, you could convert pointer-to-constant-char to pointer-to-char
>without any cast or diagnostic, which leads to obvious problems.  Here's an
>example.  (I write `char const' instead of `const char' because it's clearer
>if you always make `const' follow the type that it modifies.)
>	char const *c = "abc";
>	char const **cc;
>	char *p;
>	char **pp = &p;
>	cc = pp; /* violates C constraint */
>	*cc = c;
>	*p = 0; /* assigns to read-only storage */
>If C allowed such assignments, the line marked ``violates C constraint'' above
>would be strictly conforming C, and there would be no compile-time diagnostic
>for the problem in the last line that (at least on my machine) makes the
>program dump core.

If C allowed such assignments, the program would still not be strictly
conforming, because the last line modifies "an object with a const-qualified
type though use of an lvalue with non-const-qualified type".  Losing the
compile-time diagnostic is regrettable, but note that there is no diagnostic
required by the following:

	#include <string.h>

		*strchr("hammer me", ' ') = 0;

even though it also modifies an object with const-qualified type.

Allowing such assignments would allow correct programs to be written with
less gratuitous noise.
Technical Details
Message-ID: <11457@ksr.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!world!ksr!jfw
References: <1611@imec.UUCP> <11434@ksr.com> <#+x+b8wen@twinsun.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!world!ksr!jfw
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.std.c
Subject: Re: const T **
Keywords: const
Message-ID: <11457@ksr.com>
Date: 15 Apr 92 11:42:21 EDT
References: <1611@imec.UUCP> <11434@ksr.com> <#+x+b8wen@twinsun.com>
Sender: news@ksr.com
Lines: 36