I am experiencing a problem while using mpir library in C++. Is it possible to return mpz_t value from a function? When I try to do it, I have the following error:
RSA.cpp:50:36: error: ‘HASHtemp’ declared as function returning an array
mpz_t RSA::HASHtemp( mpz_t message )
No, it's not possible. The type
mpz_tis defined as an array type:and a function cannot return an array.
It means that you can define an object of type
mpz_tand then pass it as an argument to a function, allowing the function to modify its value (since arrays decay to pointers).In a comment, you wrote:
The documentation shows a couple of macros, not actual functions,
mpq_numrefandmpq_numden, that it describes as returningmpz_tvalues. In fact they both yield a result whose type is a pointer to the element type of thempz_tarray (__mpz_struct*). That value can be passed to a function that's documented as taking anmpz_targument, but in fact all such functions take pointer arguments.C and C++ do not permit either parameters of array type or functions returning array values, but they have several features that let you write code that looks as if that were possible. An expression of array type is, in most contexts, converted to a pointer, and a function parameter of array type is "adjusted" to be a pointer parameter. (Personally, I'm not a huge fan of the way GMP / MPIR takes advantage of this.)