_ptr and _srcptr types

Niels Möller nisse at lysator.liu.se
Sat May 19 21:27:30 UTC 2018

Vincent Lefevre <vincent at vinc17.net> writes:

> I've just noticed that GMP provides mpz_inits, so that mpz_ptr is
> necessary: Since type checking cannot be done with variadic functions,
> one must provide types compatible with mpz_ptr, or the behavior is
> undefined. This is not an issue for mpz_t variables, but the last
> argument needs to be (mpz_ptr) 0 or equivalent.

Isn't (void*) 0 good enough to get defined behavior? (For which NULL is
an alias in most C (but not C++) compilers).


As far as I've understood, the C standard requires NULL to expand to
either 0 or ((void*)0), and all sane compilers do the latter. While the
C++ standard requires NULL to expand to 0, which means that C++ code
calling mpz_inits can't use NULL to terminate the argument list, it
should probably use nullptr instead. 

(And I think at least g++ tries to work around this strange C++ quirk by
expanding NULL to some magic *slightly* different from 0, which will
produce some warnings if it used as an integer rather then pointer).


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

More information about the gmp-devel mailing list