Public mpz_ptr and mpz_srcptr
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,
foo (mpz_t x)
seems to give a compilation error (returning an array). While
foo (mpz_ptr 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:
foo (mpz_t a, mpz_t b)
mpz_add (c, a, b);
More information about the gmp-devel