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

Aaron Lehmann aaronl@vitelus.com
Wed, 27 Aug 2003 23:00:16 -0700


Hello,

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));
mpz_init(y);
mpz_init(z);
...
x[0][0] = y[0];
x[1][0] = z[0];
...
mpz_mul(x[2], x[1], x[0]);
etc

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.