When a function has an alternate entry, is it necessary to set the return value for the entry name, or will the primary name always work if the alternate name is not set? 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
Citing the Fortran 2008 Standard, Cl. 12.6.2.6 ENTRY statement:
[...]
3 If the ENTRY statement is in a function subprogram, an additional function is defined by that subprogram. The name of the function is entry-name and the name of its result variable is result-name or is entry-name if no result-name is provided. [...] If the characteristics of the result of the function named 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 need not be the same. Otherwise, they are storage associated and shall all be nonpointer, nonallocatable scalars that are default integer, default real, double precision real, default complex, or default logical.
The way I read the highlighted passage is that the line
myfunc2 = myfunc
is indeed not required since MYFUNC and MYFUNC2 are both scalar integers of the same kind.
Since no result is specified with either the function statement nor the entry statement, the function name becomes result-name. This is specified in Cl. 12.6.2.2 Function subprogram
[...]
4 If RESULT appears, the name of the result variable of the function is result-name and all occurrences of the function name in execution-part statements in its scope refer to the function itself. If RESULT does not appear, the name of the result variable is function-name and all occurrences of the function name in execution-part statements in its scope are references to the result variable. [...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With