I gather that we’re allowed to pass a pointer actual argument to a non-pointer dummy argument, but doing so allows us to create aliasing situations that presumably the compiler doesn’t know about.
Consider the following example program. Even though j
points to i
, and the dummy arguments of sub
do not have the pointer
or target
attributes, this compiles. Is this program standard-conforming? If so, what’s actually happening? It looks to me like I’ve just created a situation where the arguments alias, which I thought wasn’t allowed.
program example
integer, target :: i(10)
integer, pointer :: j(:) => null()
interface
subroutine sub(p, q)
integer, dimension(:) :: p, q
end subroutine
end interface
i = 2
j => i
call sub(j, i)
end program
Edit: this question is related to, but different from a previous question I asked about pointers and aliasing: Fortran pointers, and aliasing