Previous topic |
Ada Home Page |
Index
Scope
scope:
- where does a given declaration apply?
- what declarations apply at a given point?
scope of a declaration:
- from where it is made, to the end of the subprogram that contains it
"cannot see in; can see out"
Which names are in scope?
can refer to:
- names imported via WITH (imports)
- names declared in procedures that contain the current procedure
(globals)
- locally declared names, parameters (locals)
local declaration masks global declaration of same name
AVOID global variables !
An example shows the visibility of
each name defined in a program, at different points throughout the program.
Another example also
shows the visibility of each name defined in a program, at different
points throughout the program. It also shows the the output produced when
the program is run. You need to understand the scope rules in order to
understand the output.
Scope - good practice
localise scope as far as possible
procedures
- task/subtask: local
- common operation: global
constants
- used in only 1 part of the program: local
- used in >= 2 parts of the program: global
variables
- never use globals for external values
- always use parameters for external values
- local variables for internal use
Previous topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 14 Feb 96