Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

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

Document Table of Contents

GENERIC

Statement: Declares a generic interface that is bound to a derived type-bound procedure, or specifies a generic identifier for one or more specific procedures.

The GENERIC statement takes the following form:

GENERIC [, access-spec]:: generic-spec => binding-name1 [, binding-name2]...

access-spec

(Optional) Is the PUBLIC or PRIVATE attribute. Only one can be specified. access-spec specifies the accessibility of generic-spec.

generic-spec

Is an explicit INTERFACE statement using one of the following:

The same generic-spec can be used in several generic bindings. In this case, every occurrence of the same generic-spec must have the same accessibility.

binding-spec1 [, binding-spec2,...]

Is the name of a specific procedure. It cannot be the name of a specific procedure that has been specified in an accessible generic interface with the same generic identifier. At most one of the specific names can be the same as the generic name.

Examples

Consider the following:

GENERIC :: GEN_FUNC => INT_FUNC, REAL_FUNC
GENERIC :: GEN_FUNC => CMPLX_FUNC 

If INT_FUNC, REAL_FUNC, and CMPLX_FUNC are all functions with accessible interfaces, the first GENERIC statement declares GEN_FUNC to be a generic function name which can resolve to INT_FUNC or REAL_FUNC. The second GENERIC statement extends GEN_FUNC to be resolvable to a third specific function, CMPLX_FUNC.

Consider the following:


TYPE MY_TYPE2
...   
CONTAINS
  PROCEDURE :: MYPROC => MYPROC1
  PROCEDURE,PASS(C) :: UPROC => UPROC1
  GENERIC :: OPERATOR(+) => MYPROC, UPROC
END TYPE MY_TYPE2
...
TYPE,EXTENDS(MY_TYPE2) :: MY_TYPE3
...
CONTAINS
  PROCEDURE :: MYPROC => MYPROC2
  PROCEDURE,PASS(C) :: UPROC => UPROC2
END TYPE MY_TYPE3

The type MY_TYPE3 inherits the generic operator '+'. Invoking the generic (+) invokes the specific type-bound procedure. For entities of type MY_TYPE3, that invokes the overriding actual procedure (MYPROC2 or UPROC2).