Arrays of large integers - pass by reference getting in the way

Aaron Lehmann
Wed, 27 Aug 2003 23:00:16 -0700


In my application, I need to be able to handle variable sized arrays of
mpz's. If mpz_t was a normal structure, I would just allocate the
memory that I need and use a normal array of structures. But the wierd
typedef that defines mpz_t seems to make this difficult, since you
can't assign one array to another. Is it OK to do something like this:?

mpz_t *x;
mpz_t y, z;
x = calloc(n, sizeof(mpz_t));
x[0][0] = y[0];
x[1][0] = z[0];
mpz_mul(x[2], x[1], x[0]);

I've read about mpz_array_init, but since there is "no way to free the
storage allocated by the function", I cannot use it.