G
Greg Comeau
Greg,
I understand why 'char**' is not convertible to 'const char**'. Here's
why "char**" is not convertible to "const char**". Here's how I
explain it to others. Let us see what could happen if the conversion
was allowed:
void foo(const char** strArray)
{
strArray[0] = "Hello"; // This is OK for const char**
}
Well, that's also ok for char**, since string literals are of type
char * in c. The general idea still stands, though.
The thing that irritates me is that despite all this, it's _trivial_
to violate const in C without resorting to all this.
const char foo[] = "mystring";
char *constviol = strchr(foo,*foo);
Indeed. Which is why the C++ committee plugged that hole in the
type system.
How'd they manage that? Just out of curiosity, I know it's off-topic
C++ is OT but the underlying issues may not be per se: By plugging
as many (C) type holes as possible and/or related issues: doing
stuff like making string literals const, providing a strchr overload
(the overload itself was not the desired solution but C compatibility
was desired), requiring function prototypes, disallowing implicit int,
etc. (obviously not all these are connected to strchr()).