[UP]


Manual Reference Pages  - protected (7)

NAME

protected(7f) - [FORTRAN:SPECIFICATION ATTRIBUTE] protect use associated module objects from change outside of the module

CONTENTS

Synopsis
Description
Example

SYNOPSIS

module ANY_MODULE
specification, PROTECTED :: variable_declaration
end module ANY_MODULE

DESCRIPTION

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,
o if it is a nonpointer object, it is not definable, and
* 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.
If an object has the PROTECTED attribute, all of its subobjects have the PROTECTED attribute.

EXAMPLE

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 module

The 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.


protected (7) March 19, 2019
Generated by manServer 1.08 from 91564e04-7af2-4069-8df7-c4e54a9cfad6 using man macros.