✔ Appearance ✔ Standard ✔ Console
begin record recordName dim statements... begin union dim statements end union end record
A union is used to set aside space in a record that may potentially contain more than one size variable. The following example sets aside two equal offsets within a record for variables of differing sizes:
begin record RecordWithUnion dim beforeUnion begin union dim inUnion1` dim inUnion2$ end union end record dim myTest as RecordWithUnion myTest.inUnion2$ = "COW" print myTest.inUnion1
myTest.inUnion1 is a single byte which occupies the same space as the first byte in the string
myTest.inUnion2$. In this case,
myTest.inUnion1 happens to be the length byte of the string and the
When FB encounters a
begin union statement, all
dims up to the
end union statement are examined and the largest item in the union determines the amount of space set aside by the compiler. In the example above, the union would occupy 256 bytes since the largest element in the union is a 256 byte Pascal string.
No special notes.