Public mpz_ptr and mpz_srcptr
Torbjorn Granlund
tg at gmplib.org
Mon Feb 4 13:57:16 CET 2013
nisse at lysator.liu.se (Niels Möller) writes:
gmp.h includes the following:
/* Types for function declarations in gmp files. */
/* ??? Should not pollute user name space with these ??? */
typedef const __mpz_struct *mpz_srcptr;
typedef __mpz_struct *mpz_ptr;
I'm afraid there's no better type for users, when writing code which
returns a pointer to an mpz variables. E.g,
mpz_t
foo (mpz_t x)
{
return x;
}
seems to give a compilation error (returning an array). While
mpz_ptr
foo (mpz_ptr x)
{
return x;
}
should work fine. Or otherwise, handling pointers in any variable which
isn't a formal parameter to a function. Using mpz_t * (pointer to an
array) isn't a good alternative, since you'd get a harsh warning
whenever passing such a pointer to a GMP function expecting an mpz_ptr.
Or is there any better way to write the return type which I have missed?
I take it MP_INT * and __mpz_struct * are both discouraged.
The intended way of returning mpz_t variables is doing it like GMP does,
i.e., pass the destination mpz_t variables as parameters.
I chose to not provide mpz_ptr since I think it would be prone to
errors. I expect code like this to be created:
mpz_ptr
foo (mpz_t a, mpz_t b)
{
mpz_t c;
mpz_init (c);
mpz_add (c, a, b);
return c;
}
--
Torbjörn
More information about the gmp-devel
mailing list