Records, Unions, and Namespaces
Beta Draft - Do not distribute
© 2001, By Randall Hyde
ds, Unions, and Name Spaces
This chapter discusses ho
w to declare and use record (structures), unions, and name spaces in your pro
After strings and arrays, records are among the most commonly used composite data types; indeed,
records are the mechanism you use to create user
ned composite data types.
y assembly language
er bother to learn ho
w to use records in
assembly language, yet w
er consider not
using them in high le
el language programs.
This is some
what inconsistent since records (structures) are
just as useful in assembly language programs as in high le
el language programs.
en that you use
records in assembly language (and especially HLA) in a manner quite similar to high le
el languages, there
really is no reason for e
xcluding this important tool from your programmer’
s tool chest.
unions and name spaces f
ar less often than records, their presence in the HLA language is crucial for man
This brief chapter pro
vides all the information you need to successfully use records,
unions, and name spaces within your HLA programs.
Another major composite data structure is the P
ogy is probably better
, since it tends to a
oid confusion with the more general term
HLA uses the term “record” we’
ll adopt that term here.
Whereas an array is homogeneous, whose elements are all the same, the elements in a record can be of
Arrays let you select a particular element via an inte
ith records, you must select an
wn as a
) by name.
The whole purpose of a record is to let you encapsulate dif
ut logically related, data into a single
ascal record declaration for a student is probably the most typical e
Name: string ;
ascal compilers allocate each fi
eld in a record to contiguous memory locations.
This means that
ascal will reserv
e the fi
rst 65 bytes for the name
, the ne
o bytes hold the major code, the ne
xt 12 the
Social Security Number
In HLA, you can also create structure types using the RECORD/ENDRECORD declaration.
encode the abo
e record in HLA as follo
1. It also goes by some other names in other languages, but most people recognize at least one of these names.
2. Strings require an extra byte, in addition to all the characters in the string, to encode the length.