Please enable JavaScript to view this site.

ESL Documentation

You can also nest one structure inside another, by defining a field as a structure. There are two ways to do this. One way is to specify a previously defined structure type as the type of a field; for example:

 

structure AddressRecord is

stringStreet
City
State
Zip 

end structure

 

structure EmergencyContactRecord is

string        Name 

structure        AddressRecord Address 

string        Phone

end structure

 

In this example, first the structure type AddressRecord is defined, containing four named string fields. Then the structure type EmergencyContactRecord is defined, containing a string field called Name, a field called Address whose type is the structure type AddressRecord, and another string field called Phone.

 

The other way to nest one structure inside another is to insert a complete structure definition followed by one or more field names; for example:

 

structure AddressBook is 

string FirstName 

string LastName 

string WorkPhone 

string HomePhone

structure AddressRecord is 

stringStreet
City
State
Zip

end structure 

WorkAddress 

HomeAddress 

end structure

 

This example shows a structure type definition called AddressBook. This structure contains six fields:  four strings called FirstName, LastName, WorkPhone, and Homephone, and two structure fields called WorkAddress and HomeAddress. These two structure fields have a type of structure AddressRecord.

 

Note that when you define a structure type within another structure type, the nested type is local to the parent structure, and cannot be referenced outside that structure. In the example above, you could not reference the type structure AddressRecord to define a field in another structure. You also could not reference the nested type definition to declare a structure variable.