🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #7

Re: Questions about conversions of pointer-to-qualified types.

#7
From: Stanley Friesen
Date: Tue, 27 Oct 1992 17:35
69 lines
2507 bytes
In article <1992Oct27.073329.6679@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
|
|I'm having a hard time understanding just what the standard says (let
|alone what it means) when it comes to implicit conversions of one
|pointer type to another.
|
|Here is an example of what I mean...
|
|		void *vp;
|		char const *ccp;
|
|			vp = ccp;
|
|I'm fairly sure that this assignment is legal (even though I think it
|shouldn't have been permitted by x3j11).

No, it is not legal.  This is identical in `meaning' to:
	void *vp;
	const char *ccp;
		vp = ccp;
[The order of "const" and "char" does not matter].

The constraints on assignment to/from a void pointer are:
	- one operand is a pointer to an object or incomplete type and the
	other is a pointer to a qualified or unqualified version of void,
	and the type pointed to by the *left* [operand] has *all* *the*
	*qualifiers* of the type pointed to by the right.
[emphasis mine] [this is in section 3.3.16.1]

In this case the type pointed to by the right operand has the qualifier
"const", the type pointed to by the left is unqualified. Thus the constraint
is violated.

Section 3.3.16.1 is one of the most important for *implicit* conversions.

|Now, what about this:
|
|		const void *cvp;
|		char *cp;
|
|			cp = cvp;
|
|Is *that* assignment permitted?

No, for the same reason, based on the same text.

|Now section 3.2.2.3 seems pretty clear, but I know that there are other
|bits of relevant stuff hiding elsewhere in the standard (but I'm not
|sure where anymore).

True, and note that it only blesses conversions that *add* qualifiers,
not ones that remove them.

|(Note that "void" comes up a lot in the standard in different contexts.
|For example, 3.3.4 seems to say that:
|
|		int i;
|
|			... (const void) i;
|
|... is illegal!

Yep, though in this case the "const" doesn't add anything, this says
take the value of "i" and throw it away.

-- 
sarima@teradata.com			(formerly tdatirv!sarima)
  or
Stanley.Friesen@ElSegundoCA.ncr.com
Technical Details
Message-ID: <1323@tdat.teradata.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!tdat!swf
References: <1992Oct27.073329.6679@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!tdat!swf
From: swf@teradata.com (Stanley Friesen)
Newsgroups: comp.std.c
Subject: Re: Questions about conversions of pointer-to-qualified types.
Message-ID: <1323@tdat.teradata.COM>
Date: 27 Oct 92 17:35:21 GMT
References: <1992Oct27.073329.6679@netcom.com>
Sender: news@tdat.teradata.COM
Reply-To: swf@tdat.teradata.com (Stanley Friesen)
Organization: NCR Teradata Database Business Unit
Lines: 69