PRIVATE
Purpose
The PRIVATE attribute specifies that a module entity is not accessible outside the module through use association.
Syntax
Rules
The PRIVATE attribute can appear only in the scope of a module.
Although multiple PRIVATE statements can appear in a module, you can only include one statement that omits an access_id_list. A PRIVATE statement without an access_id_list sets the default accessibility to private for all potentially accessible entities in the module. If the module contains such a statement, it must not include a PUBLIC statement without an access_id_list. If the module does not contain a PRIVATE statement without an access_id_list, the default accessibility is public. Entities whose accessibility is not explicitly specified have default accessibility.
A procedure that has a generic identifier that is public is accessible through that identifier, even if its specific identifier is private. If a module procedure contains a private dummy argument or function result whose type has private accessibility, the module procedure must be declared to have private accessibility and must not have a generic identifier that has public accessibility. The accessibility of a derived type does not affect, and is not affected by, the accessibility of its components or procedures.
A namelist group must be private if it contains any object that is private or contains private components. A subprogram must be private if any of its arguments are of a derived type that is private. A function must be private if its result variable is of a derived type that is private.
ALLOCATABLE 1 | INTRINSIC | SAVE |
ASYNCHRONOUS | PARAMETER | STATIC 3 |
CONTIGUOUS 2 | POINTER | TARGET |
DIMENSION | PROTECTED 1 | VOLATILE |
EXTERNAL | ||
Note:
|
Examples
MODULE MC
PUBLIC ! Default accessibility declared as public
INTERFACE GEN
MODULE PROCEDURE SUB1, SUB2
END INTERFACE
PRIVATE SUB1 ! SUB1 declared as private
CONTAINS
SUBROUTINE SUB1(I)
INTEGER I
I = I + 1
END SUBROUTINE SUB1
SUBROUTINE SUB2(I,J)
I = I + J
END SUBROUTINE
END MODULE MC
PROGRAM ABC
USE MC
K = 5
CALL GEN(K) ! SUB1 referenced because GEN has public
! accessibility and appropriate argument
! is passed
CALL SUB2(K,4)
PRINT *, K ! Value printed is 10
END PROGRAM