CLASS specifier

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

CLASS ( derived-type-name )
CLASS ( * )

An entity declared with the CLASS specifier must be a dummy argument, a pointer, or allocatable.

<Semantics>

The CLASS specifier with a type name declares an entity to be polymorphic, with the declared type of the derived-type-name; this must be the name of an extensible type (i.e. not a SEQUENCE or BIND(C) type).

The dynamic type of a polymorphic entity may vary at runtime.

The dynamic type of a polymorphic variable can be tested using the SELECT TYPE construct. Outside of a SELECT TYPE construct, only components of the declared type can be accessed directly.

The CLASS ( * ) specifier declares an “unlimited polymorphic” entity. Such an entity can take on any type at all at runtime, including intrinsic types and non-extensible derived types.

The intrinsic types are allowed in TYPE IS statements, however non-extensible derived types are not permitted in TYPE IS or CLASS IS. Instead, an unsafe pointer assignment is permitted from a non-extensible derived type pointer to a CLASS (*) target; it is the user's responsibility to keep track of the actual type in the case of non-extensible types and to ensure that only correct pointer assignments are done.

<Related>

CLASS DEFAULT statement, CLASS IS statement, Derived Type definition, EXTENDS clause, EXTENDS_TYPE_OF intrinsic function, SAME_TYPE_AS intrinsic function, SELECT TYPE statement, TYPE statement, Type Declaration statement, TYPE IS statement