logoalt Hacker News

dnauticsyesterday at 8:18 PM1 replyview on HN

i could be wrong but i believe the zig compiler reserves the right to lay things out differently depending on compilation mode? especially debug. unless it's extern or packed, in which case the layout will be defined.


Replies

rvrbyesterday at 8:29 PM

`extern` and `packed` container types have well defined layouts. a regular `struct` is an "auto" layout - and the compiler can and will rearrange whenever it wants.

if you need a well defined layout, use `extern`. if your struct makes sense to represent as an integer, use `packed`. I think it is often ill advisable to use `packed` otherwise.

you can explore this yourself on the Type info returned from @TypeInfo(T):

https://ziglang.org/documentation/master/std/#std.builtin.Ty...

https://ziglang.org/documentation/master/std/#std.builtin.Ty...

https://ziglang.org/documentation/master/std/#std.builtin.Ty...

show 2 replies