Skip to main content

Union

A union type is a type in which all members derive their values from a shared space in memory. A memory block of bytes is sized based on the largest item in the union type. When any member of the union is assigned, the memory block assumes the bytes of the assigned member. When any member of the union is accessed, the member assumes the value of the bytes of the memory block.

Syntax

TYPE <UnionName> :
UNION
// members
END_UNION
END_TYPE

Sample

TYPE U_Combined :
UNION
a : INT;
b : CHAR;
END_UNION
END_TYPE

VAR
union : U_Combined;
END_VAR

union.a := 65;
print(union.b); // 'A'