Public mpz_ptr and mpz_srcptr

Vincent Lefevre vincent at vinc17.net
Mon Feb 4 14:21:54 CET 2013


On 2013-02-04 13:57:16 +0100, Torbjorn Granlund wrote:
> I chose to not provide mpz_ptr since I think it would be prone to
> errors.  I expect code like this to be created:
> 
> mpz_ptr
> foo (mpz_t a, mpz_t b)
> {
>   mpz_t c;
>   mpz_init (c);
>   mpz_add (c, a, b);
>   return c;
> }

This is not specific to GMP: every C coder should know that returning
a local variable is incorrect. A good compiler (like GCC) should be
able to detect that and output a warning (GCC does that by default).
So, in practice, there are no risks of errors.

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


More information about the gmp-devel mailing list