🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2502

Re: Qualification conversions & const safety

#2502
From: J. Kanze
Date: Fri, 10 Nov 1995 19:19
42 lines
2157 bytes
Greg McGary (gkm@magilla.cichlid.com) wrote:

|> According to sec. 4.4: Qualification conversions, paragraph 3, the
|> following is NOT a const-safe conversion:

|>  char * *  --> char const * *

|> whereas this is safe:

|>  char * *  --> char const *const *

|> Why?  I don't see how *adding* `const' an any level of a multi-level
|> pointer could lessen safety.

Consider the following:

    char const      c = 'a' ;
    char*           p ;
    char**          pp = &p ;
    char const**    ppc = pp ;      //  Supposing that this were not
                                    //      illegal
    *pp = &c ;						//	Oops: where does p point
    *p = 'b' ;                      //  And what is wrong here?

This was first pointed out during the development of the C standard, and
the standard was changed to eliminate the implicit casts for all but the
first level below the top.  During the C++ standardization, it was
pointed out that this went too far, and so the slightly looser rules of
C++ were adapted.  One of the members of the standards committee
actually proved that the current rules are optimal; everything safe is
allowed, and everything dangerous (like the above) is forbidden.
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
              -- A la recherche d'une activité dans une region francophone

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <47vp0l$96o@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <47rvj7$d2i@magilla.magilla.cichlid.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.std.c++
Subject: Re: Qualification conversions & const safety
Date: 10 Nov 1995 19:19:56 GMT
Organization: GABI Software, Sarl.
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <47vp0l$96o@gabi.gabi-soft.fr>
References: <47rvj7$d2i@magilla.magilla.cichlid.com>
NNTP-Posting-Host: physics2.berkeley.edu