GCC 3.3 and MSVS 6.0 have no problem converting char*[] to const
char*[] (not even a warning), but MS's WinCE compiler generated an
error complained that this was not possible. MS's WinCE compiler did
allow a conversion from char*[] to const char** though.
I'm interested in what the standard would say about this. (I don't
have a copy.)
You can't convert anything to an array in C, ever. (Although in C99 or
GNUC you can _construct_ an array value with a compound literal.)
If you're talking about passing arguments to a function parameter
declared 'const char * []', remember that such a declaration is
'adjusted' to 'const char * *'. If you try to pass a 'char * []', it
first decays to 'char * *' and then you are trying to convert that as
by assignment to 'const char * *' which isn't allowed, and should be
diagnosed by any compiler. Are you sure you are running each compiler
in a mode (i.e., with options) that tries to conform to the standard?
For gcc try -ansi (or -std=c99 if you prefer) and -pedantic and
preferably -Wall; for MSVC6 /Za /W4, or in the IDE there is a tickbox
somewhere to "disable language extensions".
_With a cast_ the pointer conversion is permitted, and should work --
that is, the conversion itself should work, since the result's target
must have the same alignment requirement, and same representation so
accessing the actual char * as a const char * must work. Using _that_
pointer might be const-unsafe in conjunction with other operations,
which is one reason the 'outer' conversion is not allowed. (This is
frequently asked, but not in the FAQ last I looked; 11.10 just says it
isn't allowed but doesn't explain why.)
- David.Thompson1 at worldnet.att.net