Structs
You will learn
How to declare a struct and a packed struct, and how many a module may hold.
pub struct Point { x: i32, y: i32 } declares a type with two fields. Fields are a name and a type, separated by commas. A packed struct lays its fields next to each other with no padding, the shape a hardware register has. A module may declare several structs; the lesson spec has two, and the verdict stays clean on all 7 backends.
Try it
Add a field z: i32 to Point and check which backends still compile it.

A t27 struct and a packed struct drawn as tables of fields, with how many backends compiled them. Lesson 17 of the t27 basics course.
specs/basics/17_structs.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 17: Structs.
; A struct groups named fields, each with its own type.
module basics_17_structs;
pub struct Point {
x: i32,
y: i32,
}
pub const Flags = packed struct {
ready: bool,
error: bool,
};
pub const FIELDS_IN_POINT : u8 = 2;
test a_point_has_two_fields {
assert FIELDS_IN_POINT == 2;
}
All lessons
Module 1 · A spec file
What a .t27 file holds: a module line, prose lines and comments.
Module 2 · Values and types
Constants, the width of a whole number, and true, false and text.
Module 3 · Arrays, trits and expressions
Lists of values, the three values of a trit, and what operators compute.
Module 4 · Tests and functions
A test block, several small tests in one spec, and a function with typed inputs.
Module 5 · Inside a function
Names with let and var, choices with if and switch, and loops.
Module 6 · Visibility and your own types
What pub shares with other modules, and the structs and enums you declare.
Module 7 · Modules, rules and gen-ts
Reading another module, stating a rule that always holds, and a spec turned into TypeScript.
Module 8 · The compiler and tri
The backends t27c writes, the stages it reads a spec in, and the tri command.
Module 9 · Errors, a program, what next
Reading a compiler error, one small complete program, and the course to take next.