Return value from function with alternate notation
If the function has an alias, is it necessary to set a return value for the record name, or will the base name work if no alias is given? For example,
INTEGER FUNCTION MYFUNC( ARG )
INTEGER ARG
INTEGER MYFUNC2
C ... do something here...
GOTO 100
ENTRY MYFUNC2( ARG )
C ... do something else here
100 CONTINUE
MYFUNC = <some value>
C .. is the next line needed, of can it be omitted?
myfunc2 = myfunc
RETURN
END
source to share
Referring to the Fortran 2008 standard, Cl. 12.6.2.6. RECORD INPUT:
[...]
3 If the ENTRY statement is in a function subroutine, the optional function is defined by that subroutine. The function name is the name of the input and the name of its result variable - the name of the result or the name of the input if no result name is specified. [...] If the characteristics of the result of the function specified in the ENTRY statement are the same as the characteristics of the result of the function named in the FUNCTION statement, their result variables identify the same variable, although their names do not need to be the same. Otherwise they are stored and they will all be non-overlapping, unallocated scalars, which are integer by default, real by default, double precision real, default complex or boolean by default.
The way I read the selection is that the line
myfunc2 = myfunc
You do not really need, since MYFUNC
and MYFUNC2
are both scalar integer.
Since no is result
specified with either a function statement or an input statement, the function name becomes the name of result. This is stated in Cl. 12.6.2.2 Function subroutine
[...]
4 If RESULT appears, the function result variable name is the result name and all occurrences of the function name in the execution statement within its scope refer to the function itself. If RESULT is not displayed, the result variable name is the function name and all occurrences of the function name in the execution statements in their scope are references to the result variable. [...]
source to share