1

I have a function with the following declaration:

static void FindStrColumnHeaderSpacing(const char * const *str);

When I call it with a char** variable, gmake throws:

warning: passing argument 1 of 'FindStrColumnHeaderSpacing' from incompatible pointer type
inq.c:1402:13: note: expected 'const char * const*' but argument is of type 'char **'

Now, my understanding has always been that sending a pointer to non-const data as a parameter to a function "upgrades" the pointer's data to becoming const, without issue. Does this only apply to the first (or last) layer of indirection?

What would be the problem in simply accepting char** in such a case? After all, a const char * const * parameter is a promise that the function won't change the memory block pointed by the pointer, nor will it change the actual data stored in that memory. And hell, even if the function broke that promise, the passed variable is entirely non-const, so it wouldn't even care.

Wasabi
  • 2,879
  • 3
  • 26
  • 48

0 Answers0