GMP: Is Self-Assessment Prohibited?

I'm using the arbitrary precision GMP library in C. All the use cases I've seen seem to avoid self-assignments like:

Syntax : void mpz_add (mpz_t rop, const mpz_t op1, const mpz_t op2)

mpz_add(a, a, b); // Assign a+b to a

      

Is this use permitted or should I only resort to assigning a third variable?

+3


source to share


1 answer


There is nothing wrong with self-naming as such. In fact, the documentation is exactly the opposite. According to 3.4 Variable Conventions:



GMP allows you to use the same variable for input and output in the same call. For example, the main function for integer multiplication, mpz_mul, can be used to square x and return the result at x with

 mpz_mul (x, x, x);

      

+6


source







All Articles