Table of contents for Ada as a Second Language

[Main page for Ada as a Second Language]


Preface


Chapter 1. An Introduction to Ada

1.1 The Text of an Ada Program

1.2 Notation for Ada Syntax

1.3 An Overview of Ada

1.3.1 Compilation Units
1.3.2 Subprograms and Main Programs
1.3.3 Statements
1.3.4 A Closer Look at Subprograms
1.3.5 Defining New Types
1.3.6 Extending the Meanings of Operators
1.3.7 Packages
1.3.8 Children of Packages
1.3.9 Private Types
1.3.10 Object-Oriented Programming
1.3.11 Handling Unexpected Situations
1.3.12 Generic Program Units
1.3.13 Concurrent Computations
1.3.14 Low-Level Interfaces

1.4 Differences in Ada 83

1.5 Summary


Chapter 2. Elementary Ada Programming

2.1 The Structure of a Simple Program

2.2 Object Declarations

2.3 Enumeration Type Declarations

2.3.1 Manipulation of Enumeration Types
2.3.2 Predefined Enumeration Types

2.4 Statements

2.4.1 The Assignment Statement
2.4.2 The Procedure Call Statement, Input, and Output
2.4.2.1 Procedure Call Statements
2.4.2.2 Input and Output
2.4.3 Conditional Statements
2.4.3.1 The if Statement
2.4.3.2 The case Statement
2.4.4 The null Statement
2.4.5 The loop Statement
2.4.5.1 The while Loop
2.4.5.2 The for Loop
2.4.5.3 The Basic Loop
2.4.6 The exit Statement
2.4.7 The raise Statement
2.4.8 The goto Statement
2.4.9 The return Statement
2.4.10 The delay Statement
2.4.11 Block Statements

2.5 Using Separately Compiled Facilities

2.5.1 Context Clauses
2.5.2 Using Generic Templates

2.6 Predefined Facilities

2.6.1 Command-Line Parameters and Return Codes
2.6.2 Time and Date
2.6.3 Mathematical Functions
2.6.3.1 Roots, Logarithms, and Exponents
2.6.3.2 Trigonometric Functions
2.6.3.3 Hyperbolic Functions
2.6.4 Random Values

2.7 Differences in Ada 83

2.8 Summary


Chapter 3. Type Declarations

3.1 Introduction to Programmer-Defined Types

3.1.1 Abstract Data Types
3.1.2 Kinds of Data Types
3.1.2.1 Enumeration Types
3.1.2.2 Integer Types
3.1.2.3 Floating-Point Types
3.1.2.4 Fixed-Point Types
3.1.2.5 Array Types
3.1.2.6 Record Types
3.1.2.7 Tagged Types
3.1.2.8 Access Types
3.1.2.9 Task Types
3.1.2.10 Protected Types
3.1.2.11 Private Types

3.2 The Form of a Type Declaration

3.3 Integer Type Declarations

3.3.1 Signed Integer Types
3.3.2 Modular Integer Types

3.4 Discrete Types

3.5 Floating-Point Type Declarations

3.6 Fixed-Point Type Declarations

3.6.1 Ordinary Fixed-Point Type Declarations
3.6.2 Decimal Fixed-Point Type Declarations

3.7 Named Numbers and Universal Expressions

3.8 Array Type Declarations

3.8.1 Constrained Array Types
3.8.2 Unconstrained Array Types
3.8.3 Attributes of Arrays and Array Types

3.9 Record Type Declarations

3.10 Complex Numbers

3.11 More About Enumeration Type Declarations

3.12 Evaluation of Expressions in Declarations

3.13 "One-of-a-Kind" Arrays

3.14 Differences in Ada 83

3.15 Summary


Chapter 4. Subtypes Versus Distinct Types

4.1 Type Restrictions on the Use of Data

4.2 Subtypes

4.2.1 Subtype Declarations
4.2.2 Compatibility Between Subtype Names and Constraints
4.2.2.1 Range Constraints
4.2.2.2 Digits Constraints
4.2.2.3 Index Constraints
4.2.2.4 Accuracy Constraints
4.2.2.5 Summary
4.2.3 Subtypes of Array Indices
4.2.4 Subtypes of Array and Record Components
4.2.5 Predefined Subtypes

4.3 Differences Between Types and Subtypes

4.4 Attributes of Subtypes

4.5 Derived Types

4.6 Base Subtypes

4.7 Differences in Ada 83

4.8 Summary


Chapter 5. String Manipulation

5.1 Fixed-Length, Bounded-Length, and Unbounded-Length String Types

5.2 Constructing String Values

5.3 Dealing with Bounded-Length Strings That Are Too Long

5.4 Moving, Truncating, and Padding Fixed-Length Strings

5.5 Extracting and Replacing Individual Characters

5.6 Extracting, Inserting, Deleting, and Replacing Substrings

5.7 Producing Strings of a Particular Width

5.8 Sets of Characters and Character Translation

5.9 Translating, Searching, and Decomposing Strings

5.10 Comparing Strings

5.11 Picture-Directed Editing

5.11.1 Internal Representations of Pictures
5.11.2 Generation of Edited Output
5.11.3 Localization
5.11.4 Picture Strings
5.11.4.1 Digits and Fill Characters
5.11.4.2 Zeroes, Slashes, and Group Separators
5.11.4.3 Radix Marks (Decimal Points)
5.11.4.4 Currency Symbols
5.11.4.5 Distinguishing Negative Values
5.11.4.6 Replication Factors
5.11.4.7 Special Cases
5.11.5 Blank-When-Zero Pictures
5.11.6 Determining Properties of a Picture
5.11.7 Exceptions in Generating and Using Pictures

5.12 Manipulating Strings of Wide Characters

5.13 Differences in Ada 83

5.14 Summary


Chapter 6. Expressions

6.1 Elementary Expressions

6.1.1 Literals
6.1.1.1 Numeric Literals
6.1.1.2 String Literals
6.1.1.3 Enumeration Literals
6.1.2 Names
6.1.3 Qualified Expressions
6.1.4 Aggregates
6.1.4.1 Array Aggregates
6.1.4.2 Record Aggregates
6.1.5 Type Conversions
6.1.6 Allocators
6.1.7 Function Calls

6.2 Compound Expressions

6.2.1 Exponentiation
6.2.2 Absolute Value
6.2.3 Multiplication and Division
6.2.4 Remainder
6.2.5 Plus and Minus
6.2.6 Concatenation
6.2.7 Relational Operators and Membership Tests
6.2.8 Logical Operators and Short-Circuit Control Forms
6.2.8.1 Logical Operators Applied to Boolean Values
6.2.8.2 Logical Operators Applied to Vectors of Boolean Values
6.2.8.3 Short-Circuit Control Forms
6.2.8.4 Parentheses in Logical Expressions
6.2.8.5 Special Rules for Types Derived from Boolean

6.3 Static Expressions and Static Subtypes

6.4 Universal Expressions

6.5 Differences in Ada 83

6.6 Summary


Chapter 7. Subprograms

7.1 Procedure Bodies

7.2 Function Bodies

7.3 Subprogram Specifications and Declarations

7.4 Subprogram Calls

7.5 Recursive Subprograms

7.6 Overloading

7.6.1 Overloading Subprograms
7.6.2 Defining New Meanings for Operators
7.6.3 Additional Details

7.7 Nesting Subprograms

7.8 The Inline Pragma

7.9 The Process of Passing Parameters

7.10 Differences in Ada 83

7.11 Summary


Chapter 8. Access Types

8.1 Naming Objects Designated by Access Values

8.2 Aliased and Dynamically Allocated Objects

8.2.1 Aliased Objects
8.2.2 Dynamically Allocated Objects

8.3 Access-to-Object-Type Declarations

8.4 Access-to-Subprogram-Type Declarations

8.5 The Use of Access Types

8.5.1 Selecting the Object or Subprogram Playing a Certain Role
8.5.2 Shared Data
8.5.3 Reducing Copying of Data
8.5.4 Pointing to Arrays of Various Sizes
8.5.5 Table-Driven Subprogram Invocation
8.5.6 Recursive Data Types

8.6 Subtypes of Access Types

8.7 Access Values as Subprogram Parameters

8.8 Lifetimes of Access Types and the Entities They Point To

8.9 Conversions Among Access Types

8.10 Differences in Ada 83

8.11 Summary


Chapter 9. Types with Discriminants

9.1 Records with Varying Structure

9.2 Declaring Record Types with Discriminants

9.2.1 Declaring Record Types with Variants
9.2.2 Declaring Record Types with Variable-Length Components
9.2.3 Declaring Types Whose Components Have Discriminants
9.2.4 Allowable Uses of Discriminants

9.3 Subtypes of Types with Discriminants

9.3.1 Mutable and Immutable Records

9.4 Pointing to Objects with Discriminants

9.4.1 Allocators for Records with Discriminants
9.4.2 Discriminant Constraints for Access Types

9.5 Subprogram Parameters with Discriminants

9.6 Full Form of a Discriminant Constraint

9.7 Position of Discriminants in Record Aggregates

9.8 When Expressions Are Evaluated

9.9 Differences in Ada 83

9.10 Summary


Chapter 10. Packages

10.1 Package Declarations and Package Bodies

10.2 The Syntax of Packages

10.3 The Placement and Lifetime of a Package

10.4 Children of Packages

10.5 Fractions Revisited

10.6 use Clauses

10.7 Renaming Declarations

10.8 Packages Without Bodies

10.9 Differences in Ada 83

10.10 Summary


Chapter 11. Private and Limited Types

11.1 Abstract Data Types Versus Internal Representations

11.2 Declaration of Private Types

11.3 Children of Packages With Private Parts

11.4 Deferred Constants

11.5 Programmer-Defined Equality and Inequality

11.6 Limited Types

11.7 Returning Objects by Reference

11.8 Private Types With Discriminants

11.8.1 Example: A Private Type for Varying Character Strings
11.8.2 Indefinite Private Types
11.8.3 Access Discriminants

11.9 Differences in Ada 83

11.10 Summary


Chapter 12. Classwide Programming

12.1 Object-Oriented Programming Concepts

12.1.1 Data Abstraction
12.1.2 Inheritance
12.1.3 Polymorphism

12.2 Derived Types

12.3 Type Extension

12.3.1 Conversions Among Tagged Types
12.3.2 Extension Aggregates
12.3.3 Type Extensions and Information Hiding
12.3.4 Implementing a Private Extension with an Intermediate Type
12.3.5 Type Extensions and Child Packages
12.3.6 Limited Tagged Types

12.4 Classwide Types

12.4.1 Creating Pointers to Objects of Classwide Types
12.4.2 Conversions Involving Classwide Types
12.4.3 Classwide Subprograms
12.4.4 Dispatching Operations
12.4.4.1 Controlling Dispatching
12.4.4.2 Dispatching Based on Function Results
12.4.4.3 Operations on Values with Mixed Tags
12.4.4.4 Redispatching
12.4.4.5 When to Use Classwide Subprograms and When to Use Dispatching Subprograms
12.4.4.6 Explicitly Testing for Tag Values
12.4.4.7 Private Dispatching Subprograms
12.4.5 Abstract Types and Abstract Subprograms
12.4.5.1 Inherited Functions Returning Results of a Tagged Derived Type
12.4.5.2 Abstract Subprograms of Untagged Types
12.4.6 Types Whose Operations Make Them Mutually Dependent

12.5 Automatic Initialization and Finalization

12.5.1 The Package Ada.Finalization
12.5.2 When Operations on Controlled Types Take Place

12.6 Details

12.6.1 Derived Types with Discriminants
12.6.1.1 Discriminants of Untagged Derived Types
12.6.1.2 Discriminants of Tagged Derived Types
12.6.2 Creating Pointers to Tagged-Type Formal Parameters
12.6.3 Lifetimes of Tagged Types and Their Extensions
12.6.4 Equality Operations for Types with Tagged Components

12.7 Differences in Ada 83

12.8 Summary


Chapter 13. Separate Compilation

13.1 The Compilation Environment

13.1.1 Program Libraries
13.1.2 Other Realizations of Compilation Environments

13.2 Compilation Units and Compilations

13.3 Subunits

13.4 Semantic Dependence and Order of Compilation

13.4.1 Top-Down Development and Independent Development
13.4.2 Recompilation

13.5 Elaboration of Compilation Units

13.6 Differences in Ada 83

13.7 Summary


Chapter 14. Exceptions

14.1 Handling Exceptions

14.1.1 Exceptions in Sequences of Statements
14.1.2 Exceptions Raised by Declarations
14.1.3 Exceptions Raised in Handlers

14.2 Propagation of Exceptions

14.2.1 Propagation from Block Statements
14.2.2 Propagation from Subprogram Bodies
14.2.3 Propagation from Packages

14.3 Predefined Exceptions

14.3.1 Constraint_Error
14.3.2 Program_Error
14.3.3 Storage_Error
14.3.4 Unpredictability in the Raising of Predefined Exceptions

14.4 Programmer-Defined Exceptions

14.5 Exception Occurrences

14.6 Exceptions and Finalization

14.6.1 Finalization Due to the Raising of an Exception
14.6.2 Exceptions Raised During Finalization

14.7 When Errors Are Caught

14.8 Suppressing Run-Time Checks

14.9 Differences in Ada 83

14.10 Summary


Chapter 15. Generic Units

15.1 Templates and Instances

15.2 Generic Formal Parameters

15.2.1 Generic Formal Objects
15.2.2 Generic Formal Subprograms
15.2.3 Generic Formal Types
15.2.3.1 Generic Formal Parameters for Numeric Types
15.2.3.2 Generic Formal Discrete Types
15.2.3.3 Generic Formal Array Types
15.2.3.4 Generic Formal Access Types
15.2.3.5 Generic Formal Private Types
15.2.3.6 Generic Formal Tagged Types
15.2.3.7 Generic Formal Derived Types
15.2.3.8 Generic Formal Types with Discriminants
15.2.4 Generic Formal Packages

15.3 Generic Child Units and Children of Generic Units

15.4 Defaults for Generic Parameters

15.4.1 Defaults for Generic Formal Constants
15.4.2 Defaults for Generic Formal Subprograms

15.5 Differences in Ada 83

15.6 Summary


Chapter 16. Predefined Input and Output

16.1 Basic Concepts

16.1.1 External and Internal Files
16.1.2 Textual and Internal-Form Input/Output
16.1.3 File Modes

16.2 An Overview of the Input/Output Packages

16.3 Manipulating External Files

16.3.1 Opening Files
16.3.2 Closing Files
16.3.3 Resetting Files
16.3.4 Determining the Status of Files
16.3.5 Exceptions

16.4 Textual Input and Output

16.4.1 Columns, Lines, and Pages
16.4.1.1 Columns, Lines, and Pages in Output Files
16.4.1.2 Columns, Lines, and Pages in Input Files
16.4.1.3 Control Characters in Textual Files
16.4.2 Versions of Get and Put
16.4.2.1 Get and Put for Signed Integer Types
16.4.2.2 Get and Put for Modular Integer Types
16.4.2.3 Get and Put for Floating-Point Types
16.4.2.4 Get and Put for Complex Types
16.4.2.5 Get and Put for Ordinary Fixed-Point Types
16.4.2.6 Get and Put for Decimal Fixed-Point Types
16.4.2.7 Get and Put for Enumeration Types
16.4.3 Interactive Input/Output and Buffering
16.4.4 Standard and Default Files
16.4.5 Output to and Input from Strings
16.4.6 Exceptions

16.5 Sequential Internal-Form Input/Output

16.6 Direct Internal-Form Input/Output

16.7 Streams

16.7.1 Sending Values of Particular Types to and from Streams
16.7.2 Internal-Form Files as Streams
16.7.3 Textual Files as Streams
16.7.4 External Tags

16.8 Differences in Ada 83

16.9 Summary


Chapter 17. Introduction to Tasks

17.1 Concurrency

17.2 Task Objects and Task Types

17.3 Activation and Termination of Tasks

17.4 Elementary Protected Objects

17.4.1 Race Conditions and Mutual Exclusion
17.4.2 Protected Objects and Protected Types
17.4.3 Protected Operations
17.4.4 Examples of Protected Types

17.5 Elementary Rendezvous

17.5.1 The accept Statement
17.5.1.1 Parameters of an accept Statement
17.5.1.2 The Usual Form of an accept Statement
17.5.1.3 accept Statements Without "Bodies"
17.5.1.4 Restriction on the Placement of acceptStatements
17.5.2 Example of Tasks Communicating by Rendezvous

17.6 Matching Identifiers

17.7 Differences in Ada 83

17.8 Summary


Chapter 18. Controlling Task Interaction

18.1 Advanced Forms of Rendezvous

18.1.1 Selective Acceptance of Entry Calls
18.1.1.1 Basic Selective Acceptance
18.1.1.2 Guards
18.1.1.3 The terminate Alternative
18.1.1.4 The delay Alternative
18.1.1.5 Selective Accepts with else Parts
18.1.2 Advanced Forms of Entry Calls
18.1.2.1 Timed Entry Calls
18.1.2.2 Conditional Entry Calls

18.2 Aborting the Actions of a Task

18.3 Requeuing

18.3.1 Requeuing from an Entry Body
18.3.2 Requeuing from an accept Statement
18.3.3 Requeuing and Cancellation of Entry Calls

18.4 Entry Families

18.5 Task Identification

18.6 Controlling Real-Time Behavior

18.6.1 Priorities
18.6.1.1 Priorities and Processor Allocation
18.6.1.2 Queuing Order and Selecting Among Entry Calls
18.6.1.3 Determining Priorities
18.6.1.4 Avoiding Priority Inversion
18.6.1.5 Task-Dispatching Policy
18.6.2 Accurate Time Measurement
18.6.3 Using a Restricted Set of Tasking Features

18.7 Potentially Blocking Operations

18.8 Shared Variables

18.8.1 Synchronized Use of Shared Variables
18.8.2 Unsynchronized Use of Shared Variables
18.8.3 Shared Variables in Package Bodies

18.9 Tasks and Exceptions

18.9.1 Exceptions in Task Bodies
18.9.2 Exceptions During Task Interaction

18.10 Tasks and Finalization

18.11 Determining the State of a Task

18.12 Differences in Ada 83

18.12.1 Using Passive Tasks in Place of Protected Objects
18.12.2 Using Successive Entry Calls in Place of Requeuing
18.12.3 Simulating Protected Actions with Passive Tasks

18.13 Summary


Chapter 19. Low-Level and Multilingual Programming

19.1 The Package System

19.1.1 Alternative Run-Time Configurations
19.1.2 Numeric Capabilities

19.2 Manipulating Raw Storage and Addresses

19.3 Interpreting Bits as Representing More Than One Type

19.4 Ascertaining and Controlling How Types are Represented

19.4.1 The Representation of an Enumeration Type
19.4.2 Floating-Point Arithmetic
19.4.2.1 Fixed-Point Arithmetic
19.4.3 The Size of Objects
19.4.4 The Positions of Record Components
19.4.5 Multiple Representations for the Same Data
19.4.6 Freezing the Representation of a Type

19.5 Storage Management

19.5.1 Programmer-Defined Allocation and Deallocation
19.5.2 Controlling the Storage Allotted to Tasks

19.6 Interrupt Handling

19.6.1 Interrupt-Handling Protected Procedures
19.6.2 Other Kinds of Interrupt Handlers

19.7 Using Ada Together With Another Language

19.7.1 Conventions, Importing, and Exporting
19.7.2 Package Interfaces
19.7.2.1 Interfaces with C
19.7.2.2 Interfaces with C++
19.7.2.3 Interfaces with COBOL
19.7.2.4 Interfaces with Fortran
19.7.3 Generating Specific Machine Instructions

19.8 Differences in Ada 83

19.9 Summary


Chapter 20. Distributed Programs

20.1 Models of a Distributed System

20.2 Interfaces Among Partitions

20.2.1 Passive Partitions
20.2.2 Remote Subprogram Calls and Their Interfaces
20.2.2.1 Remote-Types and Remote-Call-Interface Library Units
20.2.2.2 Remote Subprogram Calls
20.2.2.3 Example of a Client-Server System
20.2.2.4 Dynamically Bound Remote Subprogram Calls

20.3 Elaboration of Active Partitions

20.4 Differences in Ada 83

20.5 Summary


Appendix A. Scope and Visibility

A.1 Scope Rules

A.2 Visibility Rules

A.2.1 Nesting, Hiding, and Overriding
A.2.2 Direct Visibility and Contextual Visibility
A.2.3 The Effect of use Clauses

A.3 The Package Standard


Appendix B. Accuracy of Fixed-Point and Floating-Point Arithmetic

B.1 Floating-Point Accuracy Rules in Strict Mode

B.2 Fixed-Point Accuracy Rules in Strict Mode

B.3 Precision of Static and Universal Expressions


Appendix C. The Specialized-Needs Annexes

C.1 The Systems Programming Annex

C.2 The Real-Time Systems Annex

C.3 The Distributed Systems Annex

C.4 The Information Systems Annex

C.5 The Numerics Annex

C.6 The Safety and Security Annex


Appendix D. Predefined Library Units and the Pragmas Applied to Them


Appendix E. The Latin-1 Character Set


Index


[Main page for Ada as a Second Language]