How to convert GMP C parameter convention to something more natural?

For example, I would like to do something like this:

#include <gmp.h>
typedef mpz_t Integer;

// 
Integer F(Integer a,Integer b,Integer c,Integer d) {
    Integer ret = times(plus(a,b),plus(c,d));
}

But, GMP does not allow me to do this, obviously mpz_t is an array, so I get the error:

error: ‘F’ declared as function returning an array

So instead, I would have to do something like this:

void F(Integer ret,Integer a,Integer b,Integer c,Integer d) {
    Integer tmp1,tmp2;

    plus(tmp1,a,b);     
    plus(tmp2,c,d);     
    times(ret,tmp1,tmp2); 
}

This is unnatural and does not follow the logical way of adding C (or even mathematical) expressions. In fact, you cannot compose anything mathematically, because, apparently, you cannot return GMP numbers! If I wanted to write - for example, a simple yacc / bison parser that converted simple syntax with +, -, /, *, etc. In C code that implements these expressions using GMP, it seems to be a lot more complicated, since I will need to keep track of all the intermediate values.

, GMP ? "" mpz_t *, mpz_t? , , , ? - , ?

+2
1

gmp.h:

typedef __mpz_struct mpz_t[1];

, . : 1 ( ) :

mpz_t number;
DoubleIt(number); /* DoubleIt() operates on `number' (modifies it) as
                     it will be passed as a pointer to the real data */

, - :

mpz_t number;
DoubleIt(&number);

. , . : ( ). ​​, , . ( mpz_t "" ):

mpz_t number = ...;
number = DoubleIt(number);

() number . .

: ( ), . , , pass-by-reference (C ).

+3

All Articles