PUBLIC

Purpose

The PUBLIC attribute specifies that a module entity can be accessed by other program units through use association.

Syntax

Read syntax diagramSkip visual syntax diagram>>-PUBLIC--+------------------------+--------------------------><
           '-+----+--access_id_list-'
             '-::-'
 

access_id
is a generic specification or the name of a variable, procedure, derived type, constant, or namelist group

Rules

The PUBLIC attribute can appear only in the scope of a module.

Although multiple PUBLIC statements can appear in a module, only one statement that omits an access_id_list is permitted. A PUBLIC statement without an access_id_list sets the default accessibility to public for all potentially accessible entities in the module. If the module contains such a statement, it cannot also include a PRIVATE 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.

IBM Extension

Although an entity with public accessibility cannot have the STATIC attribute, public entities in a module are unaffected by IMPLICIT STATIC statements in the module.

End of IBM Extension
Attributes compatible with the PUBLIC attribute
Notes:
  1. Fortran 2003 Standard

Examples

MODULE MC
   PRIVATE                    ! Default accessibility declared as private
   PUBLIC GEN                 ! GEN declared as public
   INTERFACE GEN
      MODULE PROCEDURE SUB1
   END INTERFACE
   CONTAINS
      SUBROUTINE SUB1(I)
         INTEGER I
         I = I + 1
      END SUBROUTINE SUB1
END MODULE MC
PROGRAM ABC
   USE MC
   K = 5
   CALL GEN(K)                ! SUB1 referenced because GEN has public
                              !   accessibility and appropriate argument
                              !   is passed
   PRINT *, K                 ! Value printed is 6
END PROGRAM

Related information