Why does implicit conversion from non-const to con

2019-07-22 10:49发布

问题:

Possible Duplicate:
why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)
Double pointer const-correctness warnings in C

I'm passing a gchar** to a g_key_file_set_string_list which expects a const gchar * const identifier []

/* this function is part of the GLib library */
void g_key_file_set_string_list(GKeyFile *key_file,
                                const gchar *group_name,
                                const gchar *key,
                                const gchar * const list[],
                                gsize length);

const gchar **terms = malloc(sizeof(gchar*) * count);
...
...
g_key_file_set_string_list(<something>, <something>, <something>,
                           terms, count);

and GCC 4.7.1 with the options -std=c99 -pedantic gives me this

warning: passing argument 4 of 'g_key_file_set_string_list' from incompatible pointer type

note: expected 'const gchar * const*' but argument is of type 'gchar **'

AFAIK, both in C and C++, conversion to const from non-const is implicit, which is the reason we see standard functions like strcpy to take const args. Then doesn't it happen here?