Next: Struct Constructors, Up: Structs [Contents][Index]
A simple struct type definition in Poke looks like:
type Packet = struct { byte magic; uint<16> length; byte[length] data; }
The above defines a “Packet”, which consists on a magic number
encoded in a byte, a length encoded in an unsigned 16-bit integer, and
an array of length
bytes, which is the payload of the packet.
Each entry in the struct type above defines a struct field.
Each field has a type, which is mandatory, and a name, which is optional. Fields without names are not accessible (not even within the struct itself) but they are handy for expressing esoteric padding. See Padding and Alignment. Example:
type Imm64 = struct { uint<32> lo; uint<32>; uint<32> hi; }
It is not allowed to have several fields with the same name in the same struct. The compiler will complain if it finds such an occurrence.