Article View: comp.std.c
Article #4680Re: ... char * * promotion to char const * const * ...
From: John Winters
Date: Fri, 19 Jan 1996 19:38
Date: Fri, 19 Jan 1996 19:38
55 lines
2297 bytes
2297 bytes
In article <4dns28$3c5@boy.nmd.msu.ru>,
Alexander Krotoff <krotoff@such.srcc.msu.su> wrote:
>X-InCommentTo: john@polo.demon.co.uk (John Winters)
>
>john@polo.demon.co.uk (John Winters) wrote:
>> In article <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de>,
>> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
>> [snip]
>> >
>> >Originally, the C standard was going to allow this; in fact, it was
>> >going to allow all casts which added const anywhere in the type. Then
>> >someone pointed out that the conversion 'char ** -> char *const *' was
>> >unsafe. As a result, the wording was changed to only allow adding the
>> >const at the top level.
>>
>> Interesting. Could you enlighten us (well, me anyway) as to *why* it
>> is unsafe. I don't find it immediately obvious.
>
>Hello Joshn.
Who he?
>
>here is an example Joe Buck sent me this Julay.
>i did not understand it too before.
>
[snip]
>
>#include <iostream.h>
>
>int main() {
> const char ** const_ch_pp;
> char * ch_p;
> char ** ch_pp = & ch_p;
> const char const_ch = 'a';
> const char * const_ch_p = &const_ch;
>
> cout << "const_ch_p points to " << *const_ch_p << endl;
> const_ch_pp = ch_pp; // illegal, but you want it legal
> *const_ch_pp = const_ch_p; // copy const ptr to non-const ptr
> *ch_p = 'b'; // now we can change the const object
> cout << "const_ch_p points to " << *const_ch_p << endl;
>}
>
Funny, I could have sworn it said comp.std.c on the door.
>It's simply not debatable: it is unsafe to assign a char** to a const char**.
>--------------------------------------------------------------------
Yes, I understand now. I go to sleep explaining it to myself. :-)
John
--
John Winters. Wallingford, Oxon, England.
Technical Details
Message-ID:
<DLG17I.8uJ@polo.demon.co.uk>Path:
arc1-ca.pugleaf.net!zetnet.co.uk!demon!polo!johnReferences:
<4dgj8q$qin@unix.sri.com> <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de> <DLBzGB.J60@polo.demon.co.uk> <4dns28$3c5@boy.nmd.msu.ru>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!zetnet.co.uk!demon!polo!john From: john@polo.demon.co.uk (John Winters) Newsgroups: comp.std.c Subject: Re: ... char * * promotion to char const * const * ... Date: Fri, 19 Jan 1996 19:38:06 GMT Organization: Wallingford Message-ID: <DLG17I.8uJ@polo.demon.co.uk> References: <4dgj8q$qin@unix.sri.com> <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de> <DLBzGB.J60@polo.demon.co.uk> <4dns28$3c5@boy.nmd.msu.ru> X-NNTP-Posting-Host: polo.demon.co.uk