CONTAINS

Purpose

The CONTAINS statement separates the body of a main program, external subprogram, or module subprogram from any internal subprograms that it may contain. Similarly, it separates the specification part of a module Fortran 2008 beginsor submoduleFortran 2008 ends from any module subprograms.

The CONTAINS statement also introduces the procedure part of a derived-type definition.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CONTAINS----------------------------------------------------><

Rules

For a CONTAINS statement associated with subprograms, the following rules apply:
  • The CONTAINS statement cannot appear in a block data program unit or in an internal subprogram.
  • Any label of a CONTAINS statement is considered as part of the main program, subprogram, module, Fortran 2008 beginsor submoduleFortran 2008 ends that contains the CONTAINS statement.

Examples

An example of a CONTAINS statement

MODULE A
     ...
  CONTAINS               ! Module subprogram must follow
  SUBROUTINE B(X)
        ...
    CONTAINS             ! Internal subprogram must follow
    FUNCTION C(Y)
        ...
    END FUNCTION
  END SUBROUTINE
END MODULE

An example of a CONTAINS statement in a derived type definition

TYPE CUST
   INTEGER :: CUST_NUMBER
   CONTAINS
   PROCEDURE, PASS :: GET_CUST => GET_CUST_NUMBER
END TYPE CUST


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us