Next topic |
Ada Home Page |
Index
Separate compilation
Motivation
Program development is made much less complex if you are
able to do two things:
- separate "what" from "how"
- abstraction
- modularisation
- develop programs in small pieces
The first is the reason we focus on procedures as the blocks from
which a program is constructed.
The second lets us develop and test a program a bit at a time.
This makes testing and debugging simpler than if you test the
whole program all at once.
For it to be possible to develop a program a bit at a time, there
needs to be some help from the language. You need to be able to
break programs into several files, each of which is compiled
separately.
Ada library
To understand the mechanisms for separate compilation, we need
to know how the compiler makes use of the Ada library
- when first created it
contains standard information (eg TEXT_IO)
- result of every succesful compilation is placed there
- look there for needed items when compiling
A program can be compiled in pieces
- several separate compilations
- each adds one or more compilation units to library
- care: compile units in appropriate order
- bind to form executable once all are compiled
Units for separate compilation
Ada provides two mechanisms for separate compilation:
Usually a library unit is a
package.
When to use each sort of unit:
- if a procedure is defined as a sub-task, in the process of
top-down decomposition, generally prefer a subunit
- if a procedure is a useful operation
(eg bottom-up programming), generally prefer to make it a
library unit (or an element of a package, in which case the
package is the library unit).
A subunits is written to be part of a single specific program. A
library unit may be used in many programs.
Next topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 17 Feb 1996