🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #216

Re: const T **

#216
From: Paul Eggert
Date: Wed, 15 Apr 1992 01:43
23 lines
1353 bytes
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.
Technical Details
Message-ID: <#+x+b8wen@twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!ucla-cs!twinsun!eggert
References: <1611@imec.UUCP> <11434@ksr.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!ucla-cs!twinsun!eggert
From: eggert@twinsun.com (Paul Eggert)
Subject: Re: const T **
Message-ID: <#+x+b8wen@twinsun.com>
Keywords: const
Sender: usenet@twinsun.com
Nntp-Posting-Host: farside
Organization: Twin Sun, Inc
References: <1611@imec.UUCP> <11434@ksr.com>
Date: Wed, 15 Apr 1992 01:43:09 GMT
Lines: 23