受保护的模块实体
除了允许模块实体具有访问控制(是 public 或 private)模块实体还可以具有 protect 属性。受公共保护的实体可以使用相关联,但使用的实体受其使用限制。
module mod
  integer, public, protected::i=1
end module
program test
  use mod, only : i
  print *, i   ! We are allowed to get the value of i
  i = 2        ! But we can't change the value
end program test
不允许将公共受保护目标指向其模块外部
module mod
  integer, public, target, protected::i
end module mod
program test
  use mod, only : i
  integer, pointer::j
  j => i   ! Not allowed, even though we aren't changing the value of i
end program test
对于模块中的公共保护指针,限制是不同的。受保护的是指针的关联状态
module mod
  integer, public, target::j
  integer, public, protected, pointer::i => j
end module mod
program test
  use mod, only : i
  i = 2   ! We may change the value of the target, just not the association status
end program test
与变量指针一样,也可以保护过程指针,再次防止目标关联的改变。