# Proper way to ccall mutable types

**URL:** <https://discourse.julialang.org/t/proper-way-to-ccall-mutable-types/123998>\
**Category:** General Usage\
**Created:** [December 19, 2024, 8:53pm UTC](https://discourse.julialang.org/t/proper-way-to-ccall-mutable-types/123998 "2024-12-19T20:53:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattsignorelli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattsignorelli/32/221502_2.png) [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Post date:** [December 19, 2024, 8:53pm UTC](https://discourse.julialang.org/t/proper-way-to-ccall-mutable-types/123998/1 "2024-12-19T20:53:03Z")

</div>

Suppose I have a type

```julia
mutable struct MyCType
  a::Cint
  b::Ptr{Cdouble}
end

```

corresponding exactly to a struct in C. Then I call a C library which has functions like

```C
void modify_struct(myctype *a)

```

which mutates `a`. I want to call these functions from Julia and need to know which `::T` to specify it as in the `@ccall`.

[The manual says](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#man-bits-types):

> `T*` (where T represents an appropriately defined type) … Ref{T}` (T may be safely mutated only if T is an isbits type)|

Which, because `MyCType` is not an `isbits` type and I want to use the C code to mutate it, makes it sounds like I cannot use

```julia
typeof(a) == MyCType # true
@ccall modify_struct(a::Ref{MyCType})::Cvoid

```

However this seems to work completely fine. What am I missing?
