Do struct field initializations occur in well defined order?

Are the fields in the following struct guaranteed to initialize in a specific order (will the reader always read dest_mac, src_mac, then ether_type?

const ethernet_header = telegram.EthernetHeader{
            .dest_mac = try reader.readInt(u48, big),
            .src_mac = try reader.readInt(u48, big),
            .ether_type = try reader.readInt(u16, big),
        };

1 Like

this issue infers that it is well defined.

As far as I can tell, it occurs left-to-right.

It initializes with the initialization order. But it is not mentioned in the language reference.

A way around this is to have a fn read(reader) !EthernetHeader method to read in the correct order and construct your header, that works even if zig language specification change.

1 Like