Meaning of the intent for pointer dummy arguments

Dear all,

I thought, that the intent attribute for a pointer only restricts, whether the association status of the pointer can be changed within the procedure. However, two compilers (Intel, GNU) refuse to compile the code below, while NAG is fine with it. Can any of the standard experts say, whether the code is complying?

module test
  implicit none

contains

  subroutine change_pointer_target(ptr)
    ! NOTE: the pointer association is not changed, only its target
    real, pointer, intent(in) :: ptr(:)

    call random_number(ptr)
    ptr(:) = ptr + 1.0

  end subroutine change_pointer_target

end module test

[EDIT: I’ve stripped away some superfluous parts of the demonstration code]

2 Likes