|Fortran Language Reference Manual, Volume 1 - S-3692-51|
|Prev Section||Chapter 5. Declarations||Next Section|
If an external or dummy procedure is to be an actual argument to a subprogram, the procedure name must be declared EXTERNAL. (A dummy procedure is a dummy argument that is a procedure.) If an external procedure has the same name as an intrinsic procedure, again the name must be declared EXTERNAL. When this occurs, the intrinsic procedure of that name is no longer accessible to that program unit. If an intrinsic procedure is to be an actual argument, the name of the procedure must be declared INTRINSIC. The Fortran Language Reference Manual, Volume 2, discusses further the usage of these attributes.
Because only functions, not subroutines, are declared to have a type (the type of the result), only function names can appear in type declaration statements. The EXTERNAL and INTRINSIC attributes in type declaration statements therefore apply only to functions. The EXTERNAL and INTRINSIC statements can be used to specify properties of subroutines, and the EXTERNAL statement can specify block data program units. For information on block data program units, see the Fortran Language Reference Manual, Volume 2.
The following is a format for a type declaration statement with an EXTERNAL attribute:
type, EXTERNAL [, attribute_list ] :: function_name_list
Subject to the rules governing combinations of these attributes, attribute_list can contain the following:
An interface block can be used to describe the interface of an external function. A function described by an interface block has the EXTERNAL attribute by default, so the function name cannot also be given the EXTERNAL attribute by any other means. Note that an interface block specifies the EXTERNAL attribute for all procedures in the interface block, with the exception of module procedures specified in PROCEDURE statements within the block. For information on interface blocks, see the Fortran Language Reference Manual, Volume 2.
The EXTERNAL statement provides a means for declaring subroutines and block data program units, as well as functions, to be external. Its format is defined as follows:
Each external name must be the name of an external procedure, a dummy argument, or a block data program unit.
If a dummy argument is specified to be EXTERNAL, the dummy argument is a dummy procedure.
The EXTERNAL statement also confers the EXTERNAL attribute. It is subject to the same rules and restrictions as the EXTERNAL attribute.
The following examples of entity-oriented declarations:
SUBROUTINE SUB(FOCUS) INTEGER, EXTERNAL :: FOCUS LOGICAL, EXTERNAL :: SIN
The following example shows an attribute-oriented declaration:
SUBROUTINE SUB (FOCUS) INTEGER FOCUS LOGICAL SIN EXTERNAL FOCUS, SIN
FOCUS is declared to be a dummy procedure. SIN is declared to be an external procedure. Both are functions. To declare an external subroutine, the EXTERNAL statement or an interface block must be used because a subroutine does not have a type, and thus its attributes cannot be specified in a type declaration statement. The specific and generic name SIN of the intrinsic function SIN is no longer available to subroutine SUB.
The following is a format for a type declaration statement with an INTRINSIC attribute:
type, INTRINSIC [, attribute_list ] :: intrinsic_function_name_list
For attribute_list, specify one of the following attributes:
The INTRINSIC statement provides a means for declaring intrinsic subroutines, as well as functions. Its format is defined as follows:
Each intrinsic_procedure_name must be the name of an intrinsic procedure.
A name must not be declared to be both EXTERNAL and INTRINSIC in a scoping unit.
A type can be specified for an intrinsic function even though it has a type as specified in the Fortran Language Reference Manual, Volume 2. If a type is specified for the generic name of an intrinsic function, it does not remove the generic properties of the function name.
The INTRINSIC statement also confers the INTRINSIC attribute. It is subject to the same rules and restrictions as the INTRINSIC attribute.
The Cray Fortran Compiler has implemented intrinsic procedures in addition to the ones required by the standard. These procedures have the status of intrinsic procedures, but programs that use them may not be portable. It is recommended that such procedures be declared INTRINSIC to allow other processors to diagnose whether or not they are intrinsic for those processors.
The following is an example of an entity-oriented declaration:
REAL, INTRINSIC :: SIN, COS
The following is an example of an attribute-oriented declaration:
REAL SIN, COS INTRINSIC SIN, COS
Because the interfaces of intrinsic procedures are known to the compiler, it is not necessary to specify a type for them, but it is not incorrect to do so.