I read this answer, but I am still not clear:
Something like:
#include <stddef.h>
size_t
foo(const char ** str)
{
size_t i = 0;
while (*str[0])
i++;
return i;
}
int main (int argc, char ** argv)
{
foo(argv);
}
compiled as
$ gcc main.c
main.c: In function 'main':
main.c:14:7: warning: passing argument 1 of 'foo' from incompatible pointer type [-Wincompatible-pointer-types]
14 | foo(argv);
| ^~~~
| |
| char **
main.c:4:19: note: expected 'const char **' but argument is of type 'char **'
4 | foo(const char ** str)
My fundamental question is: why can't I make something more const
? What I am looking to accomplish is to say: I will not modify the characters, in this function.
To me, this seems different than the case the other answer gave, where you finagle your way into violating the const
nature of a char
.