Provides controlled
access to module entities.
Syntax
A USE statement has one of the following forms:
USE module-name [, rename-list ] |
USE module-name, ONLY : access-list |
- rename-list
is a comma-separated list of rename
- rename
is local-name => module-entity-name
- access-list
is a comma-separated
list of the following:
[local-name =>] module-entity-name
Description
The USE statement provides access to a module’s
public specifications and definitions. These include declared variables,
named constants, derived-type definitions, procedure interfaces, procedures,
generic identifiers, and namelist groups. The method of access is
called use association. Such access may be
limited by an ONLY clause on the USE statement, or the accessed entities may be renamed.
All USE statements must appear after the program unit
header statement and before any other statements. More than one USE statement may be present, including more than
one referring to the same module.
Modules may contain USE statements referring to other modules; however,
references must not directly or indirectly be recursive.
The local-name in a renaming operation is not declared: it
assumes the attributes of the module entity being renamed.
The first two forms of the USE statement make available by use association all
publicly accessible entities in the module, except that the USE statement may rename some module entities. The
third form makes available only those entities specified in access-list, with possible renaming of some module entities.
Entities made accessible by a USE statement include public entities from other modules referenced
by USE statements within the referenced module.
The same name or specifier may be made accessible by means
of two or more USE statements. Such an entity must not be referenced
in the scoping unit containing the USE statements, except where specific procedures can
be distinguished by the overload rules. A rename or ONLY clause may be used to restrict access to one name
or to rename one entity so that both are accessible.
Examples
MODULE rat_arith TYPE rat INTEGER n, d END TYPE ! Make all entities public except zero. TYPE(rat), PRIVATE, PARAMETER :: zero = rat(0,1) TYPE(rat), PUBLIC, PARAMETER :: one = rat(1,1) TYPE(rat) r1, r2 NAMELIST /nml_rat/ r1, r2 INTERFACE OPERATOR( + ) MODULE PROCEDURE rat_plus_rat, int_plus_rat END INTERFACE CONTAINS FUNCTION rat_plus_rat(l, r) END FUNCTION END MODULE PROGRAM Mine ! From the module rat_arith, access only the entities rat, ! one, r1, r2, nml_rat but use the name one_rat for the ! rational value one. USE rat_arith, ONLY: rat, one_rat => one, r1, r2, nml_rat ! The OPERATOR + for rationals and the procedures rat_plus_rat ! and int_plus_rat are not available because of the ONLY clause READ *, r2; r1 = one_rat WRITE( *, NML = nml_rat) END PROGRAM |
Related statements
MODULE
Related concepts
For information about modules, see “Modules”.