Summary
In this chapter we describe the parameterization of types by what are known as discriminants. Discriminants are components which have special properties. All composite types other than arrays can have discriminants. In this chapter we deal with the properties of discriminants in general and their use with record types (both tagged and untagged); their use with task and protected types is discussed in Chapter 20.
Discriminants can be of a discrete type or an access type. In the latter case the access type can be a named access type or it can be anonymous. A discriminant of an anonymous access type is called an access discriminant by analogy with an access parameter.
We start by dealing with discrete discriminants of untagged types.
Discriminated record types
In the record types we have seen so far there was no formal language dependency between the components. Any dependency was purely in the mind of the programmer as for example in the case of the private type Stack in Section 12.4 where the interpretation of the array S depended on the value of the integer Top.
In the case of a discriminated record type, some of the components are known as discriminants and the remaining components can depend upon these. The discriminants can be thought of as parameterizing the type and the syntax reveals this analogy.
- Type
- Chapter
- Information
- Programming in Ada 2012 , pp. 439 - 468Publisher: Cambridge University PressPrint publication year: 2014