Fortran elemental functions vs elemental subroutines
Fortan allows elemental subroutines to have intent(inout) and intent(out) arguments, but elemental functions are only allowed intent(in).
Why is that? Is it just a stylistic convention, or is there something generically different about invoking functions and calling subroutines?
In other words,
Elemental Integer Function FOO(i)
Integer, intent(in) :: i
...
FOO=something
End Function
and
Elemental Subro开发者_Python百科utine FOO(i, v)
Integer, intent(in) :: i
Integer, intent(out) :: v
...
v=something
End Subroutine
— are these implementations of FOO equivalently efficient?
There is no point in having an elemental subroutine without at least one argument marked as intent(out)
or intent(inout)
, because you have to pass the result somehow. A function has its return value, a subroutine must use its arguments. In Fortran 2008 AFAIK elemental procedures doesn't have to be pure, but it's hard to imagine a useful elemental subroutine only through its side effects.
精彩评论