| 1 | module PackedFields; |
| 2 | (* A packed record's fields are read and written wherever they sit *) |
| 3 | import Out; |
| 4 | import SYSTEM; |
| 5 | |
| 6 | type |
| 7 | Header = packed record kind: U8; len: U32; big: I64; tag: U8; end; |
| 8 | |
| 9 | proc main*; |
| 10 | var h, g: Header; b: ^U8; |
| 11 | begin |
| 12 | h.kind := 7; h.len := 0DEADBEEFH; h.big := -5; h.tag := 9; |
| 13 | INC(h.len); |
| 14 | g := h; |
| 15 | Out.int(SIZE(Header)); Out.str(" "); |
| 16 | Out.int(I64(g.kind)); Out.str(" "); |
| 17 | Out.hex(U64(g.len), 8); Out.str(" "); |
| 18 | Out.int(g.big); Out.str(" "); |
| 19 | Out.int(I64(g.tag)); Out.ln; |
| 20 | b := SYSTEM.ADR(g.kind); |
| 21 | Out.int(I64(b[1])); Out.ln; |
| 22 | end; |
| 23 | |
| 24 | end PackedFields. |