# Passing GMP variables from C(++) to Julia

**URL:** <https://discourse.julialang.org/t/passing-gmp-variables-from-c-to-julia/123167>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 27, 2024, 1:21pm UTC](https://discourse.julialang.org/t/passing-gmp-variables-from-c-to-julia/123167 "2024-11-27T13:21:39Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Questioner](https://avatars.discourse-cdn.com/v4/letter/q/e8c25b/32.png) [@Questioner](https://discourse.julialang.org/u/Questioner)\
**Post date:** [December 4, 2024, 3:38pm UTC](https://discourse.julialang.org/t/passing-gmp-variables-from-c-to-julia/123167/10 "2024-12-04T15:38:07Z")

</div>

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](https://discourse.julialang.org/t/ccall-how-to-wrap-call-by-reference-c-functions/53510/2)

C code:

```julia
#include<gmp.h>

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

```

Julia code:

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

```

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

---

_[View the full topic](https://discourse.julialang.org/t/passing-gmp-variables-from-c-to-julia/123167)._
