passing pointer arguments in fortran

前端 未结 2 1700
误落风尘
误落风尘 2021-01-21 22:00

I am wondering what is the proper way to write the following code?

PROGRAM foo

  INTEGER :: x
  REAL(KIND=8), TARGET, DIMENSION(0: 10) :: array
  REAL(KIND=8),          


        
2条回答
  •  时光说笑
    2021-01-21 22:55

    If a procedure has a dummy argument that is a pointer, then an explicit interface is required in any calling scope.

    (There are numerous things that require an explicit interface, a pointer dummy is but one.)

    You can provide that explicit interface yourself by putting an interface block for your subroutine inside the main program. An alternative and far, far, far better option is to put the subroutine inside a module and then USE that module in the main program. A third alternative is to make the subroutine an internal procedure of the calling scope.

    As of Fortran 2003, you should only use pointers if you intend to point the pointer at different things. If you are just using the pointer for something that really just behaves like a value, then you should use allocatables instead.

提交回复
热议问题