🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Pro 6, const, and type conversions

#1374
From: Eric Albert
Date: Thu, 19 Oct 2000 00:00
70 lines
2975 bytes
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.

In newsession.cp, I have this:
extern char *cursorShapeStrings[] = {
   "Block",
   "Underscore",
   "Vertical Bar"
};

And in newsession.h, this:
extern char *cursorShapeStrings[];

I also have this method in MenuUtils.h:
static SInt16 AppendCStringArray(LMenuController *controller, const char 
*strings[], short length);

And I'm calling it like this from another class that #includes 
newsession.h:
MenuUtils::AppendCStringArray(button, cursorShapeStrings, 
NUM_CURSOR_SHAPES);

where button is an LPopupButton * (a subclass of LMenuController) and 
NUM_CURSOR_SHAPES is #defined as 3.

Pro 5.3 does the type conversion from char *[] to const char *[] just 
fine, and the call to AppendCStringArray compiles and works.  In Pro 6, 
I get this error:
---
Error   : function call 'AppendCStringArray(LPopupButton *, char *[], 
int)' does not match
'MenuUtils::AppendCStringArray(LMenuController *, const char **, short)'
---

I find that strange to begin with, since I'd expect the char *[] to be 
promoted to a const char *[] without any problems, and that a const char 
*[] would be equivalent to a const char ** (at least for parameter 
passing).

Making things more interesting, if I change the method call to this:
---
MenuUtils::AppendCStringArray(button, static_cast<const char 
*[]>(cursorShapeStrings), NUM_CURSOR_SHAPES);
---
I get this error:
---
Error   : illegal explicit conversion from 'char **' to
'const char *[]'
SettingsDialog.cp line 191   tils::AppendCStringArray(button, 
static_cast<const char*[]>(cursorShapeStrings), NUM_CURSOR_SHAPES);
---
but casting to a const char ** instead of a const char *[] works.

It also compiles if I change cursorShapeStrings to be const.

So I'm confused about three things:
1) What did Pro 6 change here that would make the promotion of a char 
*[] to a const char *[] illegal?
2) Why does a static cast to const char *[] fail while a static cast to 
const char ** succeed?
3) Why does the compiler think that the signature of AppendCStringArray 
has a const char ** as the second parameter instead of a const char *[]?

Thanks in advance,
Eric

-- 
Eric Albert         ejalbert@stanford.edu
http://www.stanford.edu/~ejalbert/
Technical Details
Message-ID: <ejalbert-8448C2.14083019102000@nntp.stanford.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,dde2101fd59215f8,start
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,dde2101fd59215f8,start
X-Google-Attributes: gidf635e,public
From: Eric Albert <ejalbert@stanford.edu>
Subject: Pro 6, const, and type conversions
Date: 2000/10/19
Message-ID: <ejalbert-8448C2.14083019102000@nntp.stanford.edu>
X-Deja-AN: 683550922
User-Agent: MT-NewsWatcher/3.0 (PPC)
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac