Segmentation fault with optional arguments in Fortran functions

后端 未结 1 782
既然无缘
既然无缘 2021-01-12 18:03

I can use Fortran optional argumenrs with subroutines with intent(in) and intent(inout), but with functions optional arguments work only with

相关标签:
1条回答
  • 2021-01-12 18:17

    I found the problem, I used the variable even when not present on the fourth line (in tol = 1e-6):

    real function foo(x, tol) 
        real, intent(in) :: x
        real, optional, intent(inout) :: tol
        if( .not. present(tol) ) tol = 1e-6
        !...
    end function foo 
    

    But I would like to use it even when not present and set a default value, like when in C++ we do something like that

    double foo(double x, double tol=1e-6)
    

    Unfortunately, it seems it is not possible in Fortran.

    0 讨论(0)
提交回复
热议问题