# Working on spidev.h and spidev.c translation

**URL:** <https://discourse.julialang.org/t/working-on-spidev-h-and-spidev-c-translation/6479>\
**Category:** General Usage\
**Created:** [October 16, 2017, 4:42pm UTC](https://discourse.julialang.org/t/working-on-spidev-h-and-spidev-c-translation/6479 "2017-10-16T16:42:55Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 19, 2017, 9:43pm UTC](https://discourse.julialang.org/t/working-on-spidev-h-and-spidev-c-translation/6479/26 "2017-10-19T21:43:16Z")

</div>

> [@aytekinar](#):
>
> And in that long discussion with @yuyichao, I was also trying to understand the mechanism. By all these types of precautions that he is trying to teach us, we are either making the compiler to keep the object live until ccall finishes its job or doing what we really want to do.

Keeping the object alive is another story, which is related by was what I was trying to do after making sure the right pointer is passed in the other thread.  
Before worrying about GC safety, the main piece that’s missing here is to make the output parameter working. The only thing that needs to be done is to translate `&obj->x1` or `&x1` from C. Copying/modifying from the example in the other thread, you can do these with

```julia
x1 = Ref(obj.x1)
ccall(..., x1)
x1[]

```

and

```julia
ccall(..., pointer_from_objref(obj) + fieldoffset(typeof(obj), 1)))

```

Then see [Properly using `finalizer`, `ccall`, `cconvert` and `unsafe_convert` - #10 by yuyichao](https://discourse.julialang.org/t/properly-using-finalizer-ccall-cconvert-and-unsafe-convert/6183/10) for how to make the latter GC safe.

> [@Frank\_Applin](#):
>
> I’m just trying to get a grip on what retains it value and what doesn’t.

Other than special syntax from macros, whenever you have `f(a)` where `f` can be anything including `ccall` etc, it is impossible for it to modify the binding of `a`. It can only mutate `a` if `a` is mutable.

---

_[View the full topic](https://discourse.julialang.org/t/working-on-spidev-h-and-spidev-c-translation/6479)._
