Return 具有备用条目的函数的值
Return value from function with alternate entry
当函数有备选入口时,是否需要为入口名称设置 return 值,或者如果不设置备选名称,主名称将始终有效吗?例如,
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
引用 Fortran 2008 标准,Cl。 12.6.2.6 ENTRY 语句:
[...]
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.
我阅读突出显示的段落的方式是
行
myfunc2 = myfunc
确实不需要,因为 MYFUNC
和 MYFUNC2
都是同类标量整数。
由于在函数语句和入口语句中都没有指定result
,所以函数名变为result-name。这在 Cl 中指定。 12.6.2.2 函数子程序
[...]
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. [...]
当函数有备选入口时,是否需要为入口名称设置 return 值,或者如果不设置备选名称,主名称将始终有效吗?例如,
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
引用 Fortran 2008 标准,Cl。 12.6.2.6 ENTRY 语句:
[...]
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.
我阅读突出显示的段落的方式是
行myfunc2 = myfunc
确实不需要,因为 MYFUNC
和 MYFUNC2
都是同类标量整数。
由于在函数语句和入口语句中都没有指定result
,所以函数名变为result-name。这在 Cl 中指定。 12.6.2.2 函数子程序
[...]
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. [...]