# Pass a ref to tuple to ccall

**URL:** <https://discourse.julialang.org/t/pass-a-ref-to-tuple-to-ccall/27030>\
**Category:** General Usage\
**Tags:** ccall\
**Created:** [July 31, 2019, 12:35pm UTC](https://discourse.julialang.org/t/pass-a-ref-to-tuple-to-ccall/27030 "2019-07-31T12:35:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [July 31, 2019, 12:35pm UTC](https://discourse.julialang.org/t/pass-a-ref-to-tuple-to-ccall/27030/1 "2019-07-31T12:35:10Z")

</div>

I am calling an external C function that takes as an argument a pointer to an array of 4 chars and fills it with values.  
Myy initial attempt at a Julia wrapper was:

```julia
@inline function XXH32toCanonical(h::UInt32)::NTuple{4,UInt8}
   c = NTuple{4,UInt8}((0,0,0,0))
   ccall((:XXH32_canonicalFromHash, libxxhash), Cvoid,
         (Ptr{NTuple{4,Cuchar}}, Cuint), Ref(c), h)
   return c
end

```

This does not produce any errors, but does not work - the returned a tuple of zeros. This is probably due to the immutability of tuples.

I tried various “tricks”, including `unsafe_convert` which ended up raising a runtime `ERROR: ReadOnlyMemoryError()`  
What is the correct way of send a mutable 4 byte array to a C function?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 31, 2019, 12:37pm UTC](https://discourse.julialang.org/t/pass-a-ref-to-tuple-to-ccall/27030/2 "2019-07-31T12:37:49Z")

</div>

You can’t expect `c` to change when it is immutable. Try

```julia
c = Ref(NTuple{4,UInt8}((0,0,0,0))
ccall(...)
return c[]

```

([Calling C and Fortran Code · The Julia Language](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Passing-Pointers-for-Modifying-Inputs-1))
