Arrays of pointers

天大地大妈咪最大 提交于 2019-11-27 12:05:34

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 :: p
end type mytype

type(domainptr), dimension(3) :: dom

dom(1)%p => d01
dom(2)%p => d02
dom(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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!