Records
Records are special types, composed of fields which are built-in types, arrays, and/or other records. These are defined with:
RECORD identifier IS
type[*cexpr] id0 [ '[' cexpr ']' ]
...
END RECORD
Once defined, the RECORD identifier can be use anywhere a simple type can be used. Each individual field is accessed using '.'
Example:
RECORD eyeinfo IS
BYTE left
BYTE right
END RECORD
;
; a record can be initialized on definition as follows:
;
VAR eyeinfo eye = { 3, 4 }
;
; alternately, each field is accessed with the '.' operator:
;
eye.left = 1
eye.right = 2
;
; A more complex example. This sets eyes[0] to {1,2},
; eyes[1] to {3,4} and eyes[2] to {5,6}:
;
VAR eyeinfo eyes[5] = { { 1, 2 }, { 3, 4 }, { 5, 6 } }
;
; Finally, nested records and arrays are supported
;
RECORD face_r IS
eyeinfo eyes
BYTE nose
BYTE freckels[5]
END RECORD
VAR face_r[5] = {
{ { 1,2 }, 3, {4, 5, 6, 7, 8} },
{ { 2,1 }, 3, {8, 7, 6, 5, 4} }
}
Parent topic: Variables, Constants, Aliases