|
Like records, HLA allows you to create union constants within your HLA source files. However, because all the fields of a union occupy the same storage at runtime, union constants only let you specify a single value. The question is, "which value?" Well, when you create a union constant, you have to explicitly specify the field whose value you want provide. You do this using the following syntax:
typename.fieldname:[ field_value ]
The typename item must be a union type you've previously defined in a type section. The fieldname item must be a valid field from that union type. The field_value item must be an appropriate constant whose type matches the typename.fieldname field. Here is a quick example:
type utype: union b:byte; c:char; w:word; endunion; const u :utype := utype.c[ 'c' ];
You can also create union constants for anonymous unions. Obviously, such constants may only appear inside a record constant (because anonymous unions always appear within a record). The union, however, doesn't have a name associated with it, so you cannot use the previous syntax for such a constant. Instead, substitute union for the typename item in the union constant. Here's an example of an anonymous union constant (using the VariantType record type from the previous section):
const vt :VariantType := VariantType:[ 0, union.u:[0]];
Please consult the HLA Reference Manual for more details about union constants.
|