On Fri, 9 Jul 2004, george doubleu wrote:
>
> i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below.
> I get the two warnings you can see in the remarks. The second warning is
> perfectly OK for me, but the first one I don't understand.
>
> Isn't the "const int *" construct in the signature of func1 a hint for the
> user, that func1 doesn't modify **arg? Why then is it dangerous to
> pass an alterable argument?
> void func1(const int *arg[]) { }
>
> int *ary2[10];
>
> func1(ary2); // warning: passing arg 1 of `func1'
> // from incompatible pointer type
'ary2' is an 'array[10] of pointer to int'. It decays in this context
to a 'pointer to pointer to int'. That is, it is the address of a
'pointer to int'.
'func1' expects a parameter of type 'pointer to pointer to const int'.
That is, it expects the address of a 'pointer to const int'.
'pointer to int' and 'pointer to const int' are two different
types, in C. Pointers to different types are not compatible. Thus
'pointer to (pointer to int)' is not compatible with 'pointer to
(pointer to const int)'. Thus GCC gives you a warning.
How to fix it? See another thread in this newsgroup about
improper const-ifying's leading to type errors (Passing const void*
to free, or some such). Also Google for "const poisoning."
The bottom line is that this kind of error can look bizarre, but
it never occurs in well-written, real-life code, so just accept
it and you'll never see it again.
-Arthur