# Nested C structs, alignment, and "do not copy fields over"

**URL:** <https://discourse.julialang.org/t/nested-c-structs-alignment-and-do-not-copy-fields-over/124191>\
**Category:** General Usage\
**Created:** [December 26, 2024, 5:47pm UTC](https://discourse.julialang.org/t/nested-c-structs-alignment-and-do-not-copy-fields-over/124191 "2024-12-26T17:47:03Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![luke-kiernan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luke-kiernan/32/214309_2.png) [@luke-kiernan](https://discourse.julialang.org/u/luke-kiernan)\
**Post date:** [December 26, 2024, 10:06pm UTC](https://discourse.julialang.org/t/nested-c-structs-alignment-and-do-not-copy-fields-over/124191/5 "2024-12-26T22:06:12Z")

</div>

I see now: structs containing pointers can be immutable. The pointer must remain unchanged, but the pointed-to data may be overwritten just fine. The confusion stemmed from running `isbits(Inner)` (`false`), when what I really wanted was `isbitstype(Inner)` (`true`).

Still, it’s inconvenient to be unable to change the pointer. For example, if I want to use `cconvert` and `unsafe_convert` to turn something else into an `Outer`, I ought to allocate `x::Outer` inside `cconvert` then set the pointer (`x.a.p`) inside `unsafe_convert`. (See the docs [here](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#automatic-type-conversion): more detail about my specific use in [this post](https://discourse.julialang.org/t/ccall-with-a-c-struct-containing-a-pointer/124036/7).) But I can’t do that if `Inner` is immutable.

EDIT: There is a workaround, at the cost of performance: I could allocate a large enough buffer inside `cconvert`, then copy the data over inside `unsafe_convert`.

---

_[View the full topic](https://discourse.julialang.org/t/nested-c-structs-alignment-and-do-not-copy-fields-over/124191)._
