+------------------------Fortran 2003 Draft Standard-------------------------+
Purpose
The PROTECTED attribute allows greater control over the modification of module entities. A module procedure can only modify a protected module entity or its subobjects if the same module defines both the procedure and the entity.
Syntax
The PROTECTED attribute must only appear in the specification part of the module.
>>-PROTECTED--+----+--entity_declaration_list------------------>< '-::-' |
Rules
If you specify that an object declared by an EQUIVALENCE statement has the PROTECTED attribute, all objects specified in that EQUIVALENCE statement must have the PROTECTED attribute.
A nonpointer object with the PROTECTED attribute accessed through use association, is not definable.
You must not specify the PROTECTED attribute for integer pointers.
A pointer object with the PROTECTED attribute accessed through use association, must not appear as any of the following:
Attributes Compatible with the PROTECTED Attribute | ||||
---|---|---|---|---|
|
Examples
In the following example, the values of both age and val can only be modified by subroutines in the module in which they are declared:
module mod1 integer, protected :: val integer :: age protected :: age contains subroutine set_val(arg) integer arg val = arg end subroutine subroutine set_age(arg) integer arg age = arg end subroutine end module program dt_init01 use mod1 implicit none integer :: value, his_age call set_val(88) call set_age(38) value = val his_age = age print *, value, his_age end program
Related Information
+---------------------End of Fortran 2003 Draft Standard---------------------+