Lazy mpz allocation

Niels Möller nisse at
Mon Aug 31 20:13:46 UTC 2015

tg at (Torbjörn Granlund) writes:

> Unfortunately, the manual sayd "Initialize x, and set its value to 0."
> about mpz_init.

Sure, but we could do

  static const mp_limb_t dummy_limb = 0xc0dedead;

  void mpz_init (mpz_t x)
    x->_mp_size = x->_mp_alloc = 0;
    x->_mp_d = &dummy_limb;

It still represents the number zero, it's just that _mp_d[0] points to a
dummy limb which happens to be far from zero.


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