protected(7f) - [FORTRAN:SPECIFICATION ATTRIBUTE] protect use associated module objects from change outside of the module
module ANY_MODULE specification, PROTECTED :: variable_declaration end module ANY_MODULE
The PROTECTED attribute imposes limitations on the usage of module entities.The PROTECTED attribute shall be specified only in the specification part of a module.
An entity with the PROTECTED attribute shall be a procedure pointer or variable.
An entity with the PROTECTED attribute shall not be in a common block.
A nonpointer object that has the PROTECTED attribute and is accessed by use association shall not appear in a variable definition context or as the data-target or proc-target in a pointer-assignment-stmt.
A pointer that has the PROTECTED attribute and is accessed by use association shall not appear in a pointer association context
Other than within the module in which an entity is given the PROTECTED attribute, or within any of its descendants,
If an object has the PROTECTED attribute, all of its subobjects have the PROTECTED attribute.
o if it is a nonpointer object, it is not definable, and o if it is a pointer, its association status shall not be changed except that it may become undefined if its target is deallocated other than through the pointer or if its target becomes undefined by execution of a RETURN or END statement.
An example of the PROTECTED attribute:
module temperature real, protected :: temp_c, temp_f contains subroutine set_temperature_c(c) real, intent(in) :: c temp_c = c temp_f = temp_c*(9.0/5.0) + 32 end subroutine end moduleThe PROTECTED attribute ensures that the variables temp_c and temp_f cannot be modified other than via the set_temperature_c procedure, thus keeping them consistent with each other.
Nemo Release 3.1 | protected (7) | February 23, 2025 |