Crash when attempting to call mpz_invert in a program that uses mpq_class and mpz_class

Torbjörn Granlund tg at
Fri Mar 24 23:26:09 UTC 2017

Álvaro Begué <alvaro.begue at> writes:

  mpz_class fraction_mod_m(mpq_class x, mpz_class m) {
    mpz_t inverse;
    mpz_class den = x.get_den();
    mpz_invert(inverse, den.get_mpz_t(), m.get_mpz_t()); // Crashes
    return mpz_class(inverse);
No GMP bug.

Please re-read, in particular in order to use GMP
in C-style correctly.

Why do you mix C++ style and C style?

Please encrypt, key id 0xC8601622

More information about the gmp-bugs mailing list