Type-bound procedure

Standard: F77 F90 F95 F2003 F2008 Example program


A specific type-bound procedure is a procedure declared in the “type-bound procedure part” of a type definition.

specific-tbp-stmt ::= PROCEDURE [ ( interface-name ) ] , type-bound-attr-list :: binding-list
binding ::= type-bound-procedure-name [ => actual-proc-name ]
binding-list ::= binding [ , binding ]...

An interface-name is only permitted with the DEFERRED attribute, and is the name of an abstract interface or of any procedure with an explicit interface (e.g. a module procedure). An actual-proc-name is the name of a module procedure or an external procedure with an explicit interface; if it is omitted, it is assumed to be the same as the type-bound-procedure-name (except with the DEFERRED attribute).

Note that Fortran 2008 permits multiple type-bound procedure bindings to be listed on a single PROCEDURE statement, but Fortran 2003 only allows one specific binding per statement.

type-bound-attr-list ::= type-bound-attr [ , type-bound-attr ]...

type-bound-attr ::= DEFERRED
| PASS [ ( dummy-arg-name ) ]

The PUBLIC and PRIVATE attributes are only permitted in the specification part of a module. The DEFERRED attribute is only permitted in an abstract type; it requires an interface-name to be specified, and forbids an actual-proc-name.

A generic type-bound procedure is a set of specific type-bound procedures with a generic identifier; it is also declared in the “type-bound procedure part” of a type definition.

generic-tbp-stmt ::= GENERIC [ , access ] :: generic-spec => type-bound-procedure-name-list
access ::= PRIVATE | PUBLIC
type-bound-procedure-name-list ::= type-bound-procedure-name [ , type-bound-procedure-name ]...

generic-spec ::= name
| OPERATOR (operator)
| read-or-write (form)

read-or-write ::= READ | WRITE

Each type-bound-procedure-name must be the name of a specific type-bound procedure of the type being defined. The syntax for operator is described under the INTERFACE OPERATOR statement.

The syntax for invoking a specific type-bound procedure, or a named generic type-bound procedure, is similar to that of object-bound procedures:
      object % type-bound-procedure-name [ ( [ actual-arg-list ] ) ]

This syntax may appear in a CALL statement or as a function reference; as a function reference, the parentheses are required (and no alternate return specifier is permitted). The syntax of the actual-arg-list is described under the CALL statement.


Any type-bound procedure, specific or generic, may be explicitly declared to be PUBLIC or PRIVATE; otherwise, it is PRIVATE if the “type-bound procedure part” contains a PRIVATE statement, and PUBLIC otherwise; this is unaffected by a PRIVATE statement in the “component definition part”.

Each type-bound procedure statement defines a specific type-bound procedure. The name of the type-bound procedure is declared in the statement, and unless deferred is bound (for the type being defined) to the specified actual procedure. In the common case where the actual procedure is a module procedure with the same name as the type-bound procedure, the “=> actual-proc-name” may be omitted.

When extending a type, the type-bound procedures are automatically inherited from the parent type unless they are overridden by a new binding with the same name. If the type-bound procedure has the NON_OVERRIDABLE attribute, it cannot be overridden but will always be inherited as is.

Unless a type-bound procedure has the NOPASS attribute, it must have a scalar dummy argument of CLASS(type-name) matching the PASS attribute.

A type-bound procedure with the DEFERRED attribute has no associated actual procedure, but its interface is that given by interface-name. Such a procedure is only permitted in a type with the ABSTRACT attribute; objects of abstract type cannot be created, but if the abstract type is extended and the new type is not abstract and provides overrides for all of the deferred type-bound procedures, objects of the new type can be created. This allows an ABI for a family of types to be defined, with procedures that operate on them, while requiring any concrete type to provide replacements for the deferred procedures.

Each generic type-bound procedure statement either defines a new generic type-bound generic or extends an existing type-bound generic. If a type-bound generic is an operator or assignment, the PASS attribute is required on each specific type-bound procedure, and is used to determine which object is the invoking object. Note that unlike operators (and assignment) defined by an INTERFACE block, type-bound operators and assignment are always accessible whenever an object of the type is accessible, i.e. they are not blocked by the ONLY clause on a USE statement.

When a type-bound procedure is invoked via an object, the actual procedure invoked is the corresponding actual-proc-name in the definition for the dynamic type of the object.


CALL statement, CLASS specifier, Component definition statement, Derived Type Definition, EXTENDS clause, NOPASS attribute, Object-bound procedure, PASS attribute, PRIVATE attribute, PUBLIC attribute, TYPE statement