Download Language Reference Manual

Transcript
For More Information:
•
On the ENVIRONMENT attribute (Section 10.2.14)
•
On the INHERIT attribute (Section 10.2.21)
•
On the HIDDEN attribute (Section 10.2.18)
•
On declaration sections (Chapter 3)
7.5.2 Global and External Identifiers
Global and external identifiers are accessible to other compilation units (even
to compilation units written in other languages) that make up one executable
unit. The GLOBAL attribute allows a declared identifier to be globally
accessible by other compilation units; the EXTERNAL attribute specifies
that another compilation unit allocates storage for the data or routine. The
compiler does not check to make sure that global and external identifiers are
declared as being of the same data type; you must ensure that the data types
are compatible.
You cannot use global and external names to share the declarations of userdefined types. However, you can use the VALUE attribute to share global and
external literals.
The following example shows how to use global and external identifiers:
{Contained in one file:}
PROGRAM a( INPUT, OUTPUT );
VAR
Amount, Total, Tax : [EXTERNAL] REAL; {Defined elsewhere}
[EXTERNAL] PROCEDURE Calc; EXTERNAL;
{Defined elsewhere}
[GLOBAL] PROCEDURE Glf; {Body...}
{Available outside}
BEGIN
READ( Amount );
Calc;
WRITELN( ’Purchase Amount: ’, Amount:10:2)
WRITELN( ’
+ ’, Tax:10:2)
WRITELN( ’Pay This Total: ’, Total:10:2)
END.
Program Structure and Scope 7–9