Article View: comp.std.c++
Article #106Re: const
From: D'Arcy J.M. Cain
Date: Wed, 15 Apr 1992 14:59
Date: Wed, 15 Apr 1992 14:59
46 lines
2234 bytes
2234 bytes
MCCRADY@TOROLAB6.VNET.IBM.COM ("Don McCrady") writes:
>> From: donne@imec.be (Werner Donne)
>> const char **a;
>> char **b;
>> a = b;
>> Why is the assignment illegal?
>
>This has been illegal ever since C, and I assume C++ hasn't relaxed
>C's rules. The relevant rule from the assignment operator, ANSI C
>3.3.16.1, is:
Right so far.
> One of the following shall hold:
> ...
> - both operands are pointers to qualified or unqualified
> versions of compatible types... [1]
>
>[1] Omitted is the phrase "and the type pointed to by the left has
>all the qualifiers of the type pointed to by the right," which is
>irrelevant to this discussion.
Hardly irrelevant. The additional phrase says that the LHS must have
at least all of the type qualifiers (const and/or volatile - see 3.5.3)
of the RHS but the opposite isn't necessarily true.
[...]
>Note that by similar reasoning, all of the following are illegal:
> b = a;
No, this is perfectly legal. That's what the additional phrase means.
The RHS has no type qualifier so the LHS doesn't need one but the existence
of one doesn't violate the rule.
> a == b; /* or !=, or <, etc... */
> b == a; /* as above */
These are legal but from a different but similar rule in 3.3.9.
I'm not sure why the original question was posted to comp.std.c++ as well
as comp.std.c but I think this is a C standard discussion more than a C++
one. Followups redirected. Feel free to change it again if you see any
C++ specific issue.
--
D'Arcy J.M. Cain (darcy@druid) |
D'Arcy Cain Consulting | There's no government
Toronto, Ontario, Canada | like no government!
+1 416 424 2871 DoD#0082 |
Technical Details
Message-ID:
<1992Apr15.145931.7166@druid.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!jvnc.net!rutgers!news-server.csri.toronto.edu!torsqnt!geac!torag!robohack!druid!darcyReferences:
<9204141917.AA29803@ucbvax.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!jvnc.net!rutgers!news-server.csri.toronto.edu!torsqnt!geac!torag!robohack!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.std.c++,comp.std.c Subject: Re: const Message-ID: <1992Apr15.145931.7166@druid.uucp> Date: 15 Apr 92 14:59:31 GMT References: <9204141917.AA29803@ucbvax.Berkeley.EDU> Followup-To: comp.std.c Organization: D'Arcy Cain Consulting Lines: 46