Elementary Functions Fortran vs Elemental Routines

Fortan allows elementary routines to have arguments of intent (inout) and intent (out), but elementary functions are allowed only intent (in).

Why? Is it just a stylistic convention, or is there something in common that involves function calls and subprogram calls?

In other words,

Elemental Integer Function FOO(i) Integer, intent(in) :: i ... FOO=something End Function 

and

 Elemental Subroutine FOO(i, v) Integer, intent(in) :: i Integer, intent(out) :: v ... v=something End Subroutine 

Are these FOO implementations equivalently efficient?

+7
source share
1 answer

It makes no sense to have an elemental routine without at least one intent(out) or intent(inout) argument, because you must somehow pass the result. The function has a return value, the routine should use the arguments. In Fortran 2008, AFAIK elementary procedures need not be clean, but it is difficult to imagine a useful elementary routine only through its side effects.

+6
source

All Articles