Intel® Fortran Compiler 18.0 Developer Guide and Reference

PROTECTED

Statement and Attribute: Specifies limitations on the use of module entities.

The PROTECTED attribute can be specified in a type declaration statement or a PROTECTED statement, and takes one of the following forms:

Type Declaration Statement:

type, [att-ls, ] PROTECTED [, att-ls] :: entity[, entity] ...

Statement:

PROTECTED [::]entity[, entity] ...

type

Is a data type specifier.

att-ls

Is an optional list of attribute specifiers.

entity

Is the name of an entity in a module.

The PROTECTED attribute can only appear in the specification part of a module.

The PROTECTED attribute can only be specified for a procedure pointer or named variable that is not in a common block.

A non-pointer object that has the PROTECTED attribute and is accessed by use association can not appear in a variable definition or as the target in a pointer assignment statement.

A pointer object that has the PROTECTED attribute and is accessed by use association must not appear as any of the following:

The following restrictions apply outside of the module in which the entity has been given the PROTECTED attribute:

Example

The following example shows a type declaration statement specifying the PROTECTED attribute:

    INTEGER, PROTECTED :: D, E 

Consider the following example:

    MODULE counter_mod
      INTEGER, PROTECTED :: current = 0
      CONTAINS

      INTEGER FUNCTION next()
      current = current + 1    ! current can be modified here
      next = current
      RETURN
      END FUNCTION next
    END MODULE counter_mod

    PROGRAM test_counter
    USE counter_mod
    PRINT *, next( )             ! Prints 1
    current = 42                 ! Error: variable is protected
    END PROGRAM test_counter

See Also