Intel® Fortran Compiler

Developer Guide and Reference

ID 767251
Date 6/30/2025
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Procedure Pointer Assignments

This section describes procedure pointer assignment. For data pointer assignment see Pointer Assignments.

A procedure pointer has one of three states, undefined, associated, or disassociated. A procedure pointer that is not initialized is undefined until it becomes associated by procedure pointer assignment. Procedure pointer assignment has the following form:

proc_pointer => target_proc

proc_pointer

Is a procedure pointer.

proc_target

Is the name of an external procedure, internal procedure, module procedure, intrinsic procedure, dummy procedure, another procedure pointer, or a reference to the NULL intrinsic function.

Description

If proc-target is a reference to the NULL intrinsic function, the procedure pointer becomes disassociated. This is equivalent to specifying proc-pointer as a pointer object in a NULLIFY statement. If proc-target is a disassociated procedure pointer, proc-pointer becomes disassociated. If proc-target is an undefined procedure pointer, proc-pointer becomes undefined. If proc-target is a non-pointer dummy argument, proc-pointer becomes associated with the dummy argument’s ultimate argument. If proc-target is an associated procedure pointer, proc-pointer becomes associated with the same procedure. Otherwise, proc-pointer becomes associated with proc-target.

If proc-target is a specific intrinsic name that is also a generic name, proc-pointer becomes associated with only the specific procedure.

The host instance of an associated procedure pointer is the host instance of its target.

If the characteristics of proc-target or proc-pointer require an explicit interface, both proc-target and proc-pointer must have an explicit interface.

If proc-pointer has an explicit interface, its characteristics must be the same as those of proc-target, except proc-target may be pure even if proc-pointer is not pure, and proc-target may be an elemental intrinsic procedure even though proc-pointer cannot be elemental.

proc-target must be a subroutine if proc-pointer is referenced as a subroutine. proc-target must be a function if proc-pointer has an implicit interface and is explicitly typed or referenced as a function. If proc-pointer is a function with an implicit interface, proc-target must have the same type; corresponding type parameters must have the same value.

Examples

Given the following declarations:

 INTEGER(KIND=4) :: P_PTR1, P_PTR2, EXT_FUNC 
  PROCEDURE(),POINTER :: P_PTR1, P_PTR2, P_PTR3
  EXTERNAL EXT_FUNC

Then the following are examples of procedure pointer assignments:


  P_PTR1 => EXT_FUNC 
  P_PTR2 => P_PTR1
  P_PTR3 => NULL()

The following example shows procedure pointer initialization:

  
  INTEGER(KIND=4) :: P_PTR1, P_PTR2, EXT_FUNC 
  EXTERNAL EXT_FUNC
  PROCEDURE(),POINTER :: P_PTR1 => EXT_FUNC, P_PTR3 => NULL()
  PROCEDURE(),POINTER :: P_PTR2 => P_PTR1 ! Not valid in initialization; proc_targ must be NULL() or a procedure name

You can use the intrinsic function ASSOCIATED to find out if a pointer is associated, associated with a target, or if two pointers are associated with the same target. For example:

  
  INTEGER(KIND=4) :: P_PTR1, P_PTR2, EXT_FUNC 
  PROCEDURE(),POINTER :: P_PTR1, P_PTR2, P_PTR3
  EXTERNAL EXT_FUNC
 P_PTR1 => EXT_FUNC 
  P_PTR2 => P_PTR1
  P_PTR3 => NULL()
  PRINT *, ASSOCIATED (P_PTR3)           ! Prints .FALSE.
  PRINT *, ASSOCIATED (P_PTR1, EXT_FUNC) ! Prints .TRUE.
  PRINT *, ASSOCIATED (p_PTR1, P_PTR2)   ! Prints .TRUE.