How to use GMP.

Kevin Ryde user42@zip.com.au
Thu, 08 May 2003 07:43:45 +1000


Hashida <jhashida@fls.fujitsu.com> writes:
>
>         MP_INT *bbbbb=(MP_INT *)malloc(50);

You should use sizeof(MP_INT) if you really want to do it with malloc.

>         bbbbb->_mp_d=(mp_limb_t *)malloc(10);

No, gmp manages the space at _mp_d, mpz_init and friends will set it.

> aaaaa._mp_alloc=2
> aaaaa._mp_size=2
> *(aaaaa._mp_d)=2147483645

This is correct, but you need to look at _mp_d[1] too, since the value
is two limbs of 32 bits.  This is all internals though, so if you want
to be compatible with future releases, don't do it.

> Is "MP_INT" equal to "mpz_t" ?

No, with MP_INT you get a struct, with mpz_t you get a one element
array.  The difference is that for MP_INT you need to write "&x" like
you did with "&aaaaa" to get a pointer to pass.  With mpz_t that
happens automatically.