Passing GMP variables from C(++) to Julia

I’ve now managed to get it to work. The key was using pointers to pass by reference, as described here: Ccall: how to wrap call-by-reference C functions? - #2 by giordano

C code:

#include<gmp.h>

void setToTwo(mpz_t* testInt) {
	mpz_init_set_ui(*testInt, 2);
}

Julia code:

x = Ref{BigInt}(3)
@ccall "./gmptest.so".setToTwo(x::Ref{BigInt})::Cvoid

In this way, I managed to change x to 2.

2 Likes