How implement a pointer to allocatable array inside a derived data type?

This may be true within the same file, but I don’t think you can make this statement more generally if this function could be called from a separately-compiled source file.
This is important because it could be the difference between a loop being vectorised or not.

Unless the compiler is storing implementation code in .mod files[1] (which I don’t think gfortran does) or you have specified link-time optimisation (lto), then the compiler has no way to inline the definition of a function or subroutine into a separately compiled file. This is one of the advantages of C++ in that included header files allow the compiler to see and inline the body of any functions that are declared and defined there.

By comparison, the simple pointer solution does not suffer from this limitation because accessing an element in the pointer array can be inlined and vectorised.


  1. The mod files produced by ifort are often larger than those produced by gfortran, so I wondered whether they store code definitions to allow inlining, but I haven’t checked this. ↩︎