[ Table of Contents ] [ Prev ] [ Chapter Overview ] [ Glossary/Index ]
As usual, we begin with some self-test questions. (Answers are listed below in
Click Q#-# to see answer
||What are some of Ada's built-in types and subtypes?
||What are the complementary pairs of attributes applicable to enumeration
||How many characters are in the Latin-1 set, and how are these related to
the ASCII character set?
||Why are subtypes useful?
||What reserved words appear in the declaration of a fixed-point type?
||What are the attributes that apply to constrained array
types or to array objects?
||If a record type has components: Name, Age, and DOB, how
would client code that had created an object, My_Record, refer to the components
||What are the two steps of a private type declaration?
||What are the two categories of access types?
||What is a derived type?
Key points of this chapter
- Ada provides a number of built-in types (such as Boolean, Integer, Float, Character and
String) declared in package Standard, and means for creating user-defined types (such as
enumeration types, numeric types, array types, record types, access types, etc.).
- Ada provides built-in subtypes of Integer (Natural and Positive), and means for creating
subtypes (with restricted ranges of values) of previously-defined types.
- The type of a variable can sometimes be changed by performing an explicit type
- There are a number of built-in attributes that are very useful in programming (such as
'First, 'Last, 'Pos, 'Val, 'Image and 'Value for enumeration types).
- Floating-point and fixed-point types can be created with user-selected scale and
- A string is an array of components of type Character, or type Wide_Character. The
built-in type, String, is an unconstrained array declared in package Standard.
- An array can have one or more dimensions. Each dimension is associated with an index
value whose type is either Integer or an enumeration type.
- Two kinds of record types are: those without discriminants and those with discriminants.
In the former case all objects have the same kinds of components. A discriminated record
type includes one or more special elements used to parameterize the declaration.
- A private type is partially declared in the visible part of a package declaration and
fully declared in the private part of the same package declaration.
- There are two kinds of access types: pool-specific access types, which designate objects
in a storage pool, and general access types, which designate declared objects, dynamically
created objects or subprograms. Declared objects accessed this way are known as
- A derived type is defined in terms of another type called its parent type. The new type
"inherits" properties from the parent, such as components and primitive
operations. A family of types derived from a common root (children, grandchildren, etc)
are known as a "derivation class."
||A derived type is one that inherits
properties, such as components and primitive operations, from its parent type.
||Pool-specific access types, which
designate objects dynamically created by an "allocator" and general access
types, which can designate declared objects, dynamically created objects or subprograms.
||A private type is first partially declared in
the visible part of a package declaration, and then fully declared in the private part of
the same package declaration.
||The record components would be
referred to as "My_Record.Name" or "My_Record.Age" or
||The attributes of constrained
array types and array objects are 'Range, 'First, 'Last and 'Length.
||The reserved words type,
is, delta and range appear in the
declaration of a fixed-point type.
||Subtypes cause the compiler to insert
run-time checks for out-of-range conditions, and they can make programs easier to read.
||There are 256 characters in the Latin-1 set
(the same as the built-in set Character in Ada). The ASCII set consists of the first 128
characters of the Latin-1 set.
||'Image and 'Value return a string and a value,
'Pos and 'Val return a position number and a value, respectively.
||Built-in types: Boolean, Integer, Float,
Character, Wide_Character, String, Wide_String.
Built-in suybtypes: Natural, Positive.
Click here to
return to questions
This chapter has covered Ada's built-in types and how to use them in creating
user-defined types, along with illustrative examples, including the use of attributes and
type conversions. Key terms included in the Glossary/Index are:
The next chapter focuses on the classification
style of object oriented
[ Back to top of page ] [ Prev ] [ To next chapter