Arrays of pointers Arrays of pointers arrays arrays

Arrays of pointers


Yeah, pointer arrays are funny in Fortran.

The problem is that this:

TYPE(domain),DIMENSION(:),POINTER :: dom

does not define an array of pointers, as you might think, but a pointer to an array. There's a number of cool things you can do with these things in Fortran - pointing to slices of large arrays, even with strides - but it is definitely a pointer to an array, not an array of pointers.

The only way to get arrays of pointers in Fortran is to define a type:

type domainptr  type(domain), pointer :: pend type domainptrtype(domainptr), dimension(3) :: domdom(1)%p => d01dom(2)%p => d02dom(3)%p => d03

etc. As far as I can tell, the only real reason you have to do this in Fortran is syntax. I'd love to see this fixed in some later version of the standard.