There are two ways that I disagree with this characterization. First, the usual way to associate a pointer with a target is something like:
real, target :: a(N,N)
real, pointer :: apt(:,:)
...
apt => a
That is, you have the target, you have the pointer, and you assign directly from one to the other.
You are instead suggesting that the “natural” way is something like
temp => a
apt => temp
where the temp
pointer acts as an intermediate. That does not seem natural to me.
The second observation is the way the dummy argument is declared. In what I consider the natural way, the declaration is
real, intent(in), target :: a(:,:)
This reflects correctly my intentions for that dummy argument, namely that is is not changed within the subroutine and that it is a target that can be used in a pointer assignment statement. If I were to make a program mistake, say a(1,1)=newvalue
, the compiler would tell me, probably at compile time, and I would fix it immediately. Your suggestion
real, intent(in), pointer :: a(:,:)
says instead that the pointer characteristics cannot be modified, but the array itself (i.e. the target of the declared pointer) can be modified. Those characteristics are not faithful to my intentions. Indeed, if I were to make a mistake and type, a(1,1)=newvalue
, the compiler would not tell me that I had done so, it would allow me to shoot myself in the foot and then spend time later trying to find the error.
All of that seems unnatural and like a gimmick to me. I don’t know if I would ever use the pointer declaration shortcut for those reasons. I am still inclined to make the correct declarations so that the compiler, and humans reading the code, can see my intentions clearly.