
char** and const char** ...
Quote:
>Hi! I am trying to pass a char** to a function which is not expected
>to modify it. It just refers to the variable. So, the called function
>is of the form:
>int some_function (const char ** pp_c)
>{
> /* some code that does not modify pp_c, just uses its contents
> * to do its work.
> */
> return (result);
>}
>int some_other_function (/* various parameters */)
>{
> int result;
> char ** pp_c;
> /* some code not relevant */
> /* code that allocates and fills in pp_c based on passed in
>parameters */
> result = some_function (pp_c); /* !!!!!!!! */
> return (result);
>}
>This generates a compiler warning at the line marked with "!"
>character.
>Any idea why?
It would be nice of you to tell us what the warning says.
I imagine it has to do with an attempt to pass the wrong type of
pointer.
The language can convert a (T *) to a (const T *), but it won't go
deeper than that. Specifically, it can convert (char **) to
(char * const *), but it can't convert (char **) to a (const char **).
If you can't change the function signature, you can use a cast to do
the conversion:
result = some_function ( (const char **)pp_c );
Quote:
>I am writing this code on a RH8.0 linux system (gcc version 3.2). But,
>more experimentation showed the same problem repeat on RH7.3 with
>older (gcc version 2.96) compiler!
>Help! I need to get this done soon.
--