Visible to Intel only — GUID: GUID-0850206B-680F-4239-8F33-169B66C0A816
Visible to Intel only — GUID: GUID-0850206B-680F-4239-8F33-169B66C0A816
Type-Bound Procedures
In a derived-type definition, you can optionally specify a type-bound-procedure-part, which declares one or more type-bound procedures. These procedures consist of a CONTAINS statement, optionally followed by a PRIVATE statement, and one or more procedure binding statements. Type-bound procedures take the following form:
CONTAINS
[PRIVATE]
proc-binding-spec
[proc-binding-spec]...
proc-binding-spec |
Is one of the following:
|
specific-binding |
A specific type-bound procedure binds a procedure to a type or it specifies a deferred binding to an abstract type. It takes one of the following forms: PROCEDURE (interface-name), binding-attr-list :: binding-name [, binding-name]... PROCEDURE [ [ , binding-attr-list ] :: ] binding-name [ => procedure-name ] [, [binding-name [ => procedure-name]]…] |
generic-binding |
Is GENERIC [ , access-spec] :: generic-spec => binding-name-list A generic type-bound procedure defines a generic interface that is bound to the type. For more information, see the GENERIC statement. |
final-binding |
Is FINAL [::] final-subroutine-list An extensible derived type can have one or more "final subroutines" associated with it. A final subroutine can be executed to perform clean-up operations after a data entity of that type is finalized (ceases to exist). For more information, see the FINAL statement. |
interface-name |
(Optional) Is the interface for the procedure. It must be the name of an abstract interface or a procedure that has an explicit interface. interface-name can only be specified if the binding has the DEFERRED attribute. |
binding-attr-list |
(Optional) Is one or more of the following. The same attribute can only appear once for the same binding:
|
binding-name |
Is the name of the type-bound procedure. It is referred to in the same way as a component of a type. |
procedure-name |
(Optional) Is the name of the actual procedure that implements binding-name. It is the name of an accessible module procedure or an external procedure that has an explicit interface. It defines the interface for the procedure, and the procedure to be executed when the procedure is referenced. |
generic-spec |
Is one of the following:
|
The default accessibility of type-bound procedures is public even if the components are private. You can change this by including the PRIVATE statement following the CONTAINS statement. The default accessibility of type-bound procedures can be changed only in the specification part of a module.
If neither => procedure-name nor interface-name appears, the procedure-name is the same as the binding-name. If => procedure-name appears, you must specify the double-colon separator and you must not specify an interface-name.
In general, the invoking variable, the passed-object dummy argument, is passed as an additional argument. By default, this is the first dummy argument of the actual procedure. So, the first argument in the argument list becomes the second argument, etc.
A passed-object dummy argument can be changed by declaring the type-bound procedure with the PASS (arg-name) attribute. In this case, the variable is passed as the named argument. The PASS attribute can also be used to confirm the default as the first argument. The NOPASS attribute prevents passing the object as an argument.
When PASS is in effect, the call passes B to the first argument of the procedure, C to the second argument, and D to the third argument.
Consider the following:
TYPE MY_TYPE
... ! Component declarations
CONTAINS
PROCEDURE :: PROC1 => MY_PROC
PROCEDURE :: PROC2, PROC3 => MY_PROC3
PROCEDURE :: PROC4 => MY_PROC4, PROC5 => MY_PROC5
END TYPE MY_TYPE
This binds MY_PROC with the PROC1.
If B is a scalar variable of type MY_TYPE, an example of a type-bound call is:
CALL B%PROC1(C, D)