Strange gcc warning.

Roberto Bagnara bagnara at cs.unipr.it
Wed Apr 23 10:21:11 CEST 2008


ezzetabi wrote:
> Here a minimalistic example:
> /* min.c */
> #include <gmp.h> 
> void f(const mpz_t* t) {
>     t = t;
> }
> int main() {
>     mpz_t e[5];
> 
>     f(e);
>     return 0;
> }
> $ gcc -W -Wall -pedantic min.c -lgmp
> min.c: In function ‘main’:
> min.c:9: warning: passing argument 1 of ‘f’ from incompatible pointer type
> 
> Even with this warning the programs work as expected, but I was wondering if
> it is something to worry about.
> It actually seems a gcc problem to me, but I wanted to share to know if anyone
> had the same problem or knows its implications.
> 
> I saw a mpz_t is actually a __mpz_struct[1], probably gcc tries to say that
> passing a multidimensional array as simple pointer gives problem when trying
> to access the elements as you can't use the [] operator as you may expect.
> But since the first dimension of the array is actually one it still works
> fine. In this case the warning can indeed safely ignored.
> Yet, I still do not understand why this happens only when passing the pointer
> to a function that takes a points to constant pointer.
> 
> Any idea?

See 6.7.3#8 of the C99 standard and

    http://c-faq.com/ansi/constmismatch.html

All the best,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it


More information about the gmp-discuss mailing list