Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

ENTRY

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Provides an additional external or module subprogram entry point.

Syntax

ENTRY entry-name [([dummy-arg-list])
     [RESULT (result-name)]]
entry-name

is the name of the entry point (subroutine or function) defined by the ENTRY statement. It must differ from the original subroutine or function name, and from other ENTRY statement entry-names specified in the subprogram in which it appears.

dummy-arg-list

is a comma-separated list of dummy arguments for the subroutine or function defined by the ENTRY statement. The same rules and restrictions apply as for subroutine dummy arguments or function dummy arguments, as appropriate.

result-name

is the result variable for a function defined by an ENTRY statement. result-name is optional; if not specified, the result variable is entry-name.

The RESULT (result-name) clause can only be specified when the ENTRY statement is included in a function subprogram.

Description

When an ENTRY statement appears in a function subprogram, it effectively provides an additional FUNCTION statement in the subprogram: execution starts from the ENTRY statement when the entry-name is invoked (by being used). Similarly, an ENTRY statement in a subroutine subprogram effectively provides an additional SUBROUTINE statement in the subprogram, and execution starts from the ENTRY statement when the entry-name is called.

The following restrictions apply to the ENTRY statement:

  • The ENTRY statement can appear in an external subprogram or a module subprogram; it may not appear in an internal subprogram. If the ENTRY statement appears in a function subprogram, it defines an additional function; if it appears in a subroutine subprogram, it defines an additional subroutine. The entry points thus defined can be referenced in the same way as for a normal function name or subroutine name, as appropriate. Execution starts at the ENTRY statement, and continues in the normal manner, ignoring any ENTRY statements subsequently encountered, until a RETURN statement or the end of the procedure is reached.

  • The RESULT (result-name) clause can only be specified when the ENTRY statement is included in a function subprogram. If specified, result-name must differ from entry-name, and entry-name must not appear in any specification statement in the scoping unit of the function subprogram; entry-name assumes all the attributes of result-name. The RESULT clause in an ENTRY statement has the same syntax and semantics as in a FUNCTION statement.

  • If the ENTRY statement appears in a function, the result variable is that specified in the FUNCTION statement; if none is specified, the result variable is entry-name.

  • If the characteristics of the result variable specified in the ENTRY statement are the same as those of the result variable specified in the FUNCTION statement, then the result variable is the same, even though the names are different. If the characteristics are different, then the result variables must be:

    • Nonpointer scalars of intrinsic type

    • Storage associated

    • If any is of character type, they must all be of character type and must all have the same length. If any is of noncharacter type, they must all be of noncharacter type.

  • The result variable may not appear in a COMMON, DATA, or EQUIVALENCE statement. Also, the result variable may not have the ALLOCATABLE, INTENT, OPTIONAL, PARAMETER, or SAVE attribute.

  • If RECURSIVE is specified on the FUNCTION statement at the start of a function subprogram, and RESULT is specified on an ENTRY statement within the subprogram, then the interface of the function defined by the ENTRY statement is explicit within the function subprogram; the function can thus be invoked recursively. (Note that the keyword RECURSIVE is not given on the ENTRY statement, but only on the FUNCTION statement.)

  • If RECURSIVE is specified on the SUBROUTINE statement at the start of a subroutine subprogram, the interface of the subroutine defined by an ENTRY statement within the subprogram is explicit within the subprogram; the subroutine can thus be called recursively.

  • A dummy argument in an ENTRY statement must not appear in an executable statement preceding the ENTRY statement, unless it also appears in a FUNCTION, SUBROUTINE, or ENTRY statement preceding the executable statement.

  • If a dummy argument in a subprogram—that is, as specified in a FUNCTION or SUBROUTINE statement at the start of the subprogram or in any ENTRY statements within the subprogram—is used in an executable statement, then the statement may only be executed if the dummy argument appears in the dummy argument list of the procedure name actually referenced in the current call. The same restrictions apply when you use a dummy argument in a specification expression to specify an array bound or character length.

  • A procedure defined by an ENTRY statement may be given an explicit interface by use of an INTERFACE block. The procedure header in the interface body must be a FUNCTION statement for an entry to a function subprogram, and a SUBROUTINE statement for an entry to a subroutine subprogram.

The ENTRY statement was often used in FORTRAN 77 programs in situations where a set of subroutines or functions had slightly different dummy argument lists but entailed computations involving identical data and code. In Fortran 90 the use of the ENTRY statement in such situations can be replaced by the use of optional arguments.

Examples

The following example defines a subroutine subprogram with two dummy arguments. The subprogram also contains an ENTRY statement that takes only the first dummy argument specified in the SUBROUTINE statement.

SUBROUTINE Full_Name (first_name, surname)
CHARACTER(20) :: first_name, surname
...
ENTRY Part_Name (first_name)

The following example creates a stack. It shows the use of ENTRY to group the definition of a data structure together with the code that accesses it, a technique known as encapsulation. (This example could alternatively be programmed as a module, which would be preferable in that it does not rely on storage association.)

SUBROUTINE manipulate_stack
IMPLICIT NONE
INTEGER size, top /0/, value
PARAMETER (size = 100)
INTEGER, DIMENSION(size) :: stack
SAVE stack, top

ENTRY push(value) ! Push value onto the stack
IF (top == size) STOP 'Stack Overflow'
top = top + 1
stack(top) = value
RETURN

ENTRY pop(value) ! Pop top of stack and place in value
IF (top == 0) STOP 'Stack Underflow'
value = stack(top)
top = top - 1
RETURN
END SUBROUTINE manipulate_stack

Here are examples of CALL statements associated with the preceding example:

CALL push(10)
CALL push(15)
CALL pop(I)
CALL pop(J)

Related statements

FUNCTION, SUBROUTINE, and CALL

Related concepts

For information about external procedures, see “External procedures”.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.