Public mpz_ptr and mpz_srcptr

Niels Möller nisse at lysator.liu.se
Mon Feb 4 18:00:43 CET 2013


Torbjorn Granlund <tg at gmplib.org> writes:

> The intended way of returning mpz_t variables is doing it like GMP does,
> i.e., pass the destination mpz_t variables  as parameters.

Sure, that the *usual* way for a function that modifies the number.
"Make the common case easy, and the uncommon case possible..."

Here's another possible use of mpz pointers:

  void
  foo (mpz_srcptr a, mpz_srcptr b)
  {
    /* Make a <= b */
    if (mpz_cmp (a, b) > 0)
      {
        mpz_srcptr t = a;
        a = b;
        b = t;
      }
    ... further computation on a and b ...
  }

I think this is perfectly reasonable user code. And note in particular
that if the user tried mpz_swap instead, she would be shooting herself
badly in the foot.

I think using typedefed arrays in C (like mpz_t) is a hack which has to
be used with extreme care in special circumstances (and GMP may be a
valid use). Then it's pretty evil of an API to not provide *any* public
types for its abstractions, except for array typedefs.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list