ENTRY

Purpose

A function subprogram or subroutine subprogram has a primary entry point that is established through the SUBROUTINE or FUNCTION statement. The ENTRY statement establishes an alternative entry point for an external subprogram or a module subprogram.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-ENTRY--entry_name--+-------------------------------+--------->
                      '-(--+---------------------+--)-'   
                           '-dummy_argument_list-'        

   .--------------------------------------------------------.   
   V                                                        |   
>----+----------------------------------------------------+-+--><
     +-RESULT--(--result_name--)--------------------------+     
     |      (1)                                           |     
     '-BIND------(--C--+-----------------------------+--)-'     
                       '-, -NAME-- = --binding_label-'          

Notes:
  1. Fortran 2003
entry_name
is the name of an entry point in a function subprogram or subroutine subprogram
binding_label
is a scalar expression for initializing a character

Rules

The ENTRY statement cannot appear in a main program, block data program unit, internal subprogram, IF construct, DO construct, CASE construct, derived-type definition, or interface block.

The ENTRY statement cannot appear in a CRITICAL, MASTER, PARALLEL, PARALLEL SECTIONS, SECTIONS, or SINGLE construct.

An ENTRY statement can appear anywhere after the FUNCTION or SUBROUTINE statement (and after any USE statements) of an external or module subprogram, except in a statement block within a control construct, in a derived-type definition, or in an interface block. ENTRY statements are nonexecutable and do not affect control sequencing during the execution of a subprogram.

The result variable is result_name, if specified; otherwise, it is entry_name. If the characteristics of the ENTRY statement's result variable are the same as those of the FUNCTION statement's result variable, the result variables identify the same variable, even though they can have different names. Otherwise, they are storage-associated and must be all nonpointer, nonallocatable scalars of intrinsic (noncharacter) type. result_name can be the same as the result variable name specified for the FUNCTION statement or another ENTRY statement.

The result variable cannot be specified in a COMMON, DATA, integer POINTER, or EQUIVALENCE statement, nor can it have the PARAMETER, INTENT, OPTIONAL, SAVE, or VOLATILE attributes. The STATIC and AUTOMATIC attributes can be specified only when the result variable is not an allocatable object, an array or a pointer, and is not of character or derived type.

If the RESULT keyword is specified, the ENTRY statement must be within a function subprogram, entry_name must not appear in any specification statement in the scope of the function subprogram, and result_name cannot be the same as entry_name.

A result variable must not be initialized in a type declaration statement or DATA statement.

The entry name in an external subprogram is a global entity; an entry name in a module subprogram is not a global entity. An interface for an entry can appear in an interface block only when the entry name is used as the procedure name in an interface body.

At most one RESULT clause and at most one BIND clause can appear. They can appear in any order.

The BIND keyword implicitly or explicitly defines a binding label which specifies the name by which an entity is accessed from the C programming language. The result variable, if there is a result, must be a scalar that is interoperable. A binding label cannot be specified for a dummy argument. A dummy argument cannot be zero-sized. A dummy argument for a procedure with the BIND attribute must have interoperable types and type parameters, and cannot have the ALLOCATABLE, OPTIONAL, or POINTER attribute.

In a function subprogram, entry_name identifies a function and can be referenced as a function from the calling procedure. In a subroutine subprogram, entry_name identifies a subroutine and can be referenced as a subroutine from the calling procedure. When the reference is made, execution begins with the first executable statement following the ENTRY statement.

The result variable must be defined before exiting from the function, if the function is invoked through that ENTRY statement.

A name in the dummy_argument_list must not appear in the following places:
  • In an executable statement preceding the ENTRY statement unless it also appears in a FUNCTION, SUBROUTINE, or ENTRY statement that precedes the executable statement.
  • In the expression of a statement function statement, unless the name is also a dummy argument of the statement function, appears in a FUNCTION or SUBROUTINE statement, or appears in an ENTRY statement that precedes the statement function statement.

The order, number, type, and kind type parameters of the dummy arguments can differ from those of the FUNCTION or SUBROUTINE statement, or other ENTRY statements.

Suppose a dummy argument is used in a specification expression to specify an array bound or character length of an object. You can only specify the object in a statement that is executed during a procedure reference if the dummy argument is present and appears in the dummy argument list of the procedure name referenced.

Note: The ENTRY statement is marked as obsolescent in Fortran 2008 and later language standards. A warning message is generated if you use an ENTRY statement when -qlanglvl=2008pure is specified. Instead, you can use a module containing the private data item, with a module procedure for each entry point and the shared code in a private module procedure.

Recursion

An ENTRY statement can reference itself directly only if the subprogram statement specifies RECURSIVE and the ENTRY statement specifies RESULT. The entry procedure then has an explicit interface within the subprogram. The RESULT clause is not required for an entry to reference itself indirectly.

Elemental subprograms can have ENTRY statements, but the ENTRY statement cannot have the ELEMENTAL prefix. The procedure defined by the ENTRY statement is elemental if the ELEMENTAL prefix is specified in the SUBROUTINE or FUNCTION statement.

In a recursive function, if entry_name is of type character, its length cannot be represented by an asterisk (*, meaning assumed or specified elsewhere).

You can also call external procedures recursively when you specify the -qrecur compiler option, although XL Fortran disregards this option if a procedure specifies either the RECURSIVE or RESULT keyword.

Examples

RECURSIVE FUNCTION FNC() RESULT (RES)
     ⋮
  ENTRY ENT () RESULT (RES)          ! The result variable name can be
                                     ! the same as for the function
       ⋮
END FUNCTION

Related information