Purpose
The PRIVATE attribute specifies that a module entity is not accessible outside the module through use association.
Format
>>-PRIVATE--+------------------------+------------------------->< '-+----+--access_id_list-' '-::-' |
Rules
The PRIVATE attribute can appear only in the scope of a module.
Although multiple PRIVATE statements may appear in a module, only one statement that omits an access_id_list is permitted. 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 cannot also include a PUBLIC statement without an access_id_list. If the module does not contain such a statement, 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.
If a PRIVATE statement is specified within a derived-type definition, all the components of the derived type become private.
A structure must be private if its derived type is private. A namelist group must be private if it contains any object that is private or contains private components. A derived type that has a component of derived type that is private must itself be private or have 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.
Attributes Compatible with the PRIVATE Attribute | ||||
---|---|---|---|---|
|
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
Related Information