4.30 Record Constants


4.30 Record Constants

HLA lets you define record constants. In fact, HLA supports both symbolic record constants and literal record constants. Record constants are useful as initializers for static record variables. They are also quite useful as compile time data structures when using the HLA compile time language (see the HLA Reference Manual for more details on the HLA compile time language). This section discusses how to create record constants.

A literal record constant takes the following form:

           RecordTypeName:[ List_of_comma_separated_constants ] 

The RecordTypeName is the name of a record data type you've defined in an HLA type section prior to this point.

The constant list appearing between the brackets are the data items for each of the fields in the specified record. The first item in the list corresponds to the first field of the record, the second item in the list corresponds to the second field, and so on. The data types of each of the constants appearing in this list must match their respective field types. The following example demonstrates how to use a literal record constant to initialize a record variable:

 type      point:      record           x:int32;           y:int32;           z:int32;      endrecord; static      Vector: point := point:[ 1, -2, 3 ]; 

This declaration initializes Vector.x with 1, Vector.y with -2, and Vector.z with 3.

You can also create symbolic record constants by declaring record objects in the const or val sections of your program. You access fields of these symbolic record constants just as you would access the field of a record variable, using the dot operator. Because the object is a constant, you can specify the field of a record constant anywhere a constant of that field's type is legal. You can also employ symbolic record constants as record variable initializers. The following example demonstrates this:

 type      point:      record           x:int32;           y:int32;           z:int32;      endrecord; const      PointInSpace: point := point:[ 1, 2, 3 ]; static      Vector: point := PointInSpace;      XCoord: int32 := PointInSpace.x;           .           .           .      stdout.put( "Y Coordinate is ", PointInSpace.y, nl );           .           .           . 




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net