This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Warning for incompatible pointer type
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: José Luis García Pallero <jgpallero at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 29 Mar 2011 09:07:04 +0100
- Subject: Re: Warning for incompatible pointer type
- References: <AANLkTikBODDSMzLv0JQTp_YZj8dbgAT2m7bxsPZOR5Ac@mail.gmail.com>
2011/3/29 José Luis García Pallero:
> Hello,
> In the function bellow I pass two const pointers to a function. One
> pointer to a char** and the other to char*. When I compiling the
> program via gcc test.c -o test I obtain a warning:
>
> test.c:18:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type
> test.c:4:6: note: expected ‘const char **’ but argument is of type ‘char **’
>
> What is the reason for the warning? I won't change the char** argument
> in the function so I think that declare it as const is correct. What
> the argument const char* do no emits a warning? I tested the program
> with gcc 4.5.2 and 4.6.0 and I obtain the warning in each compiler.
See the C++ FAQ Lite (this question applies to both C and C++):
http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17