# Converting between type and immutable with the same layout

**URL:** <https://discourse.julialang.org/t/converting-between-type-and-immutable-with-the-same-layout/2784>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 20, 2017, 6:56pm UTC](https://discourse.julialang.org/t/converting-between-type-and-immutable-with-the-same-layout/2784 "2017-03-20T18:56:47Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [March 20, 2017, 8:33pm UTC](https://discourse.julialang.org/t/converting-between-type-and-immutable-with-the-same-layout/2784/5 "2017-03-20T20:33:53Z")

</div>

Yes, `a` is the original mutable, convention will be that this is the placeholder to prevent GC and it should be kept or the object (from C++ in this case) stored in the void pointer will be deleted by the finalizer attached to `a`. This is in fact an implementation detail for [referencing C++ objects](https://discourse.julialang.org/t/stack-allocating-wrapped-c-objects/2635). Since `MutableFoo` and `ImmutableFoo` are both created using the C API, they have no constructor attached (and I couldn’t find a way to attach one from C) so this hack allows me to convert to the stack-allocated “reference type” without using `ccall`.

---

_[View the full topic](https://discourse.julialang.org/t/converting-between-type-and-immutable-with-the-same-layout/2784)._
