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

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: more detail about my specific use in this post.) 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.

1 Like