_ptr and _srcptr types

Vincent Lefevre vincent at vinc17.net
Sat May 19 22:43:22 UTC 2018


On 2018-05-19 23:27:30 +0200, Niels Möller wrote:
> 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).

No, pointers to different types may have different representations,
and in particular, different sizes. Not sure whether there are
platforms on which this is the case. But also using a wrong pointer
type might break the generated code with aggressive optimization
(in particular with LTO).

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-devel mailing list