Automatic array deallocation in Fortran

后端 未结 2 1235
闹比i
闹比i 2021-01-05 07:03

I\'m using gfortran -std=f2008. I have a function that returns a derived type which contains an allocatable array. The function calls allocate() before it returns. It see

2条回答
  •  攒了一身酷
    2021-01-05 07:17

    Another general advice : most of the time, it is much safer to use subroutines instead of functions for returning complicated results like arrays, pointers, derived types with allocatable inside...

    Additional question : do you use your function within an expression ? If not then it should be a subroutine. Fortran functions have only interest if used within calculation expressions.

提交回复
热议问题