I am trying to pass a parameter to a function and point out that the parameter must be accepted by const by the receive function.
I realized that the following code example shows the only way to guarantee that the test function can be called using the argv variable, which is not declared as const.
void test(const char * const *arr); int main(int argc, char *argv[], char *env[]) { test(argv); } void test(const char * const *arr) { }
However, gcc gives me a warning, for example the following:
E:\Projects\test>gcc -o test test.c test.c: In function 'main': test.c:5:2: warning: passing argument 1 of 'test' from incompatible pointer type [enabled by default] test.c:1:6: note: expected 'const char * const*' but argument is of type 'char **'
It makes me think that what I'm doing here is somehow wrong. Is there a better way to pass a parameter to a function and indicate that it should be considered a const function by a receive function?
source share