Formal Definition
A composite type object is one having multiple elements. There are two classes of composite types: array types and record types.
Syntax:
composite_type_definition ::= array_type_definition | record_type_definition
Description
An object of a composite type is a collection of other objects, called elements. The elements can be of any scalar, composite or access type. It is not allowed to use file types as elements of a composite type.
The difference between arrays and records lies in that all elements of an array must be of the same type. For example, each array element can be a voltage value. On the other hand, each element of a record can be of a different type (Voltage1, current1, resistance1,Voltage2,&ldots;). Each element of an array is referred to by its array name and position (index). On the other hand, the record elements (called fields) are referred to through their individual names (together with the name of entire record), or through an aggregate.
See array and record for details.
Examples
Example 1
type T_MonthlyIncome is array (1 to 12) of Integer;
type T_PersonalData is
record
FirstName : String (1 to 6);
LastName : String (1 to 10);
IDNumber : String (1 to 5);
Incomes : T_MonthlyIncome;
TaxPaid : Boolean;
end record;
The two types above illustrate two classes of composite type. The first one defines a 12-position array of integer values, while the second one is a record with five fields. First four fields are of composite types, while the very last one is of a scalar type.
Example 2
Signal Year97Inc : T_MonthlyIncome;
Signal SomeEmployee : T_PersonalData;
. . .
Year97Inc(12) <= 5500;
SomeEmployee.FirstName <= "Gordon";
The signals are declared to be of the types declared in Example 1. Note the way elements of the composite types are accessed: in case of arrays through the position index, while in record through the field name (preceded by a dot).
No comments:
Post a Comment
Please provide valuable comments and suggestions for our motivation. Feel free to write down any query if you have regarding this post.