🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #1378

Re: Pro 6, const, and type conversions

#1378
From: Anton Rang
Date: Fri, 20 Oct 2000 00:00
55 lines
3202 bytes
In article <ejalbert-8448C2.14083019102000@nntp.stanford.edu>, Eric 
Albert <ejalbert@stanford.edu> wrote:
> I'm by no means an expert on automatic type conversions or const-ness in 
> C++, but I have some code that compiled without warnings or errors on 
> Pro 5.3 and now doesn't compile on Pro 6, and I'm wondering why.

The implicit conversion from 'char **' to 'const char **' is prohibited 
in C++; the simplest example I could come up with for this is:

  char **ary;
  const char **ary2;

  void test(void)
  {
     ary = ary2;  // fails (can't get rid of 'const' implicitly)
     ary2 = ary;  // fails (prohibited by standard)
  }

The standard explains it this way.  Consider the following sequence:

  const char c = 'c';                // a const char
  char *pc;                          // a pointer to a (non-const) char
  const char** pcc = &pc;            // *** PROHIBITED BY STANDARD ***
  *pcc = &c;                         // now pc points at c
  *pc = 'C';                         // this would modify a 'const' char

I'm not sure I fully understand the rationale here, but basically it 
seems that by turning the 'char **' into a 'const char **', you open an 
opportunity for assign a 'const char *' into a 'char *'....

Blecch.

> 1) What did Pro 6 change here that would make the promotion of a char 
> *[] to a const char *[] illegal?

  Looks like they follow the spec more closely now.

> 2) Why does a static cast to const char *[] fail while a static cast to 
> const char ** succeed?

  I'm not sure, but you probably want to use a const_cast here anyway 
since you're only affecting constness.

> 3) Why does the compiler think that the signature of AppendCStringArray 
> has a const char ** as the second parameter instead of a const char *[]?

  Because a function parameter of type "array of T" is converted to a 
parameter of type "pointer to T" when computing the signature of a 
function (section 8.3.5, paragraph 3).

  -- Anton

-- 
This is an unauthorized communication.  "The statements and opinions
expressed herein are my own and do not necessarily represent those of Adaptec."
Technical Details
Message-ID: <rang-927714.15311220102000@news.visi.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <ejalbert-8448C2.14083019102000@nntp.stanford.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,dde2101fd59215f8
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,dde2101fd59215f8
X-Google-Attributes: gidf635e,public
From: Anton Rang <rang@trillium.adaptec.com>
Subject: Re: Pro 6, const, and type conversions
Date: 2000/10/20
Message-ID: <rang-927714.15311220102000@news.visi.com>
X-Deja-AN: 683928405
References: <ejalbert-8448C2.14083019102000@nntp.stanford.edu>
Posted-And-Mailed: yes
X-Complaints-To: abuse@visi.com
X-Face: Xy2NdC^o4C6=_tfx*{V*f4z;9S^w^_UJ./MPs*&7n%{}]:L@qeSDB;OG#/XRO de(CE#joG"r)zkwk;b{7={gQ<7'zLR(NN}ez8[s$/ZJv$VC7Gbx({;]Xa#C}N^nk^Ui[ [NpQ-6^BPUTFkz24&Pz/}I`Or.kuI^1imAV>;R6I1_X.ebcDKI/j$QAB2pC?.Ct_fJXw By02{k~tnDVm|8q{
X-Trace: ptah.visi.com 972073874 208.236.45.160 (Fri, 20 Oct 2000 15:31:14 CDT)
Organization: Adaptec Trillium Development Center
User-Agent: MT-NewsWatcher/3.0 (PPC)
NNTP-Posting-Date: Fri, 20 Oct 2000 15:31:14 CDT
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac