Strange gcc warning.

ezzetabi ezzetabi at hotmail.com
Wed Apr 23 08:58:41 CEST 2008


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?
Thanks.
ezzetabi


More information about the gmp-discuss mailing list