# 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: generic-name generic-spec can be the name of a previously declared accessible generic name, in which case this statement extends that interface. For more information, see Defining Generic Names for Procedures. OPERATOR (op) op is an intrinsic or a user-defined operator. For more information, see Defining Generic Operators. ASSIGNMENT (=) See Defining Generic Assignment. 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).

Parent topic: G

## See Also

Type-Bound Procedures
Defining Generic Names for Procedures