Consider this code
program proba implicit none interface subroutine thunk() end subroutine thunk end interface type funptr procedure(thunk),pointer , nopass :: f end type funptr type(funptr) :: farr(3) farr(1)%f=>a farr(2)%f=>b farr(3)%f=>c call farr%f() contains subroutine a() print *, 'a' end subroutine a subroutine b() print *, 'b' end subroutine b subroutine c() print *, 'c' end subroutine c end program proba
If I compile this code with ifort 15.0.0 20140723 , the program prints only "a". Now, I think I have found somewhere in Metcalfs book that it is possible to access subobjects in an array of derived objects collectively, something like arr%a, instead of looping over the arr: arr(i)%a. However, in the code above, I am calling a subobject function pointer, apparently collectively since the compiler did not complain. I never knew this was possible, but the result is even more baffling. I would have expected that such an "array call" would in turn call each of the subobject functions separately, but what it does is calling only the first subroutine -- subroutine a(). Subroutines b and c are never invoked. I have used this syntax construct by accident, omitting a looping index in calls to farr(i)%f(). It looks very weird to me and I wonder if it is maybe a compiler's bug not to report such invocation. Is this anyhow possible within the Fortran standard?