pointers - Why can't I convert 'char**' to a 'const char* const*' in C? -
the following code snippet (correctly) gives warning in c , error in c++ (using gcc & g++ respectively, tested versions 3.4.5 , 4.2.1; msvc not seem care):
char **a; const char** b = a; i can understand , accept this.
c++ solution problem change b const char * const *, disallows reassignment of pointers , prevents circumventing const-correctness (c++ faq).
char **a; const char* const* b = a; however, in pure c, corrected version (using const char * const *) still gives warning, , don't understand why. there way around without using cast?
to clarify:
1) why generate warning in c? should entirely const-safe, , c++ compiler seems recognize such.
2) correct way go accepting char** parameter while saying (and having compiler enforce) not modifying characters points to? example, if wanted write function:
void f(const char* const* in) { // reads data in, not write } and wanted invoke on char**, correct type parameter?
edit: thank have responded, particularly addressed question and/or followed on responses.
i've accepted answer want cannot done without cast, regardless of whether or not should possible.
i had same problem few years ago , irked me no end.
the rules in c more stated (i.e. don't list exceptions converting char** const char*const*). consequenlty, it's not allowed. c++ standard, included more rules allow cases this.
in end, it's problem in c standard. hope next standard (or technical report) address this.
Comments
Post a Comment