XL Fortran for AIX 8.1

Language Reference

Type Declaration

Purpose

A type declaration statement specifies the type, length, and attributes of objects and functions. Initial values can be assigned to objects.

Format



>>-type_spec--+-+----+----------------+--entity_decl_list------><
              | '-::-'                |
              '-,--attr_spec_list--::-'
 
 

where:

type_spec attr_spec
BYTE (1)
CHARACTER [char_selector]
COMPLEX [kind_selector]
DOUBLE COMPLEX (1)
DOUBLE PRECISION
INTEGER [kind_selector]
LOGICAL [kind_selector]
REAL [kind_selector]
TYPE (type_name)

ALLOCATABLE
AUTOMATIC
DIMENSION (array_spec)
EXTERNAL
INTENT (intent_spec)
INTRINSIC
OPTIONAL
PARAMETER
POINTER
PRIVATE
PUBLIC
SAVE
STATIC
TARGET
VOLATILE

Notes:

  1. IBM Extension.

type_name
is the name of a derived type

kind_selector



>>-+-(--+-----------+--int_initialization_expr--)-+------------><
   |    '-KIND-- = -'                             |
   |                           (1)                |
   '- * --int_literal_constant--------------------'
 
 


Notes:


  1. IBM Extension.


 

represents one of the permissible length specifications for its associated type.

+-------------------------------IBM Extension--------------------------------+

int_literal_constant cannot specify a kind type parameter.

+----------------------------End of IBM Extension----------------------------+

char_selector

specifies the character length

+-------------------------------IBM Extension--------------------------------+

In XL Fortran, this is the number of characters between 0 and 256 MB. Values exceeding 256 MB are set to 256 MB, while negative values result in a length of zero. If not specified, the default length is 1. The kind type parameter, if specified, must be 1, which specifies the ASCII character representation.

+----------------------------End of IBM Extension----------------------------+



>>-+-(--+-LEN--=--type_param_value--,--KIND--=--int_init_expr-----+--)-+-><
   |    +-type_param_value--,--+---------+--int_init_expr---------+    |
   |    |                      '-KIND--=-'                        |    |
   |    +-KIND--=--int_init_expr--+-----------------------------+-+    |
   |    |                         '-,--LEN--=--type_param_value-' |    |
   |    '-+--------+--type_param_value----------------------------'    |
   |      '-LEN--=-'                                                   |
   '-*--char_length--+---+---------------------------------------------'
                     '-,-'
 
 

 

type_param_value
is a specification expression or an asterisk (*)

int_init_expr
is a scalar integer initialization expression that must evaluate to 1

char_length
is either a scalar integer literal constant (which cannot specify a kind type parameter) or a type_param_value enclosed in parentheses

attr_spec
For detailed information on rules about a particular attribute, refer to the statement of the same name.

intent_spec
is either IN, OUT, or INOUT

::

is the double colon separator. It is required if attributes are specified, = initialization_expr FORTRAN 95 Beginsor => NULL() FORTRAN 95 Ends is used.

array_spec
is a list of dimension bounds.

entity_decl



>>-a--+-+------------------+--+------------------+-+------------>
      | '- * --char_length-'  '-(--array_spec--)-' |
      '-(--array_spec--)-- * --char_length---------'
 
>--+-----------------------------------+-----------------------><
   |                            (1)    |
   '-+-/--initial_value_list--/------+-'
     +- = --initialization_expr------+
     |              (2)              |
     '- => --NULL()------------------'
 
 


Notes:


  1. IBM Extension

  2. Fortran 95


 

a
is an object name or function name. array_spec cannot be specified for a function name.

+-------------------------------IBM Extension--------------------------------+

char_length
overrides the length as specified in kind_selector and char_selector, and is only permitted in statements where the length can be specified with the initial keyword. A character entity can specify char_length, as defined above. A noncharacter entity can only specify an integer literal constant that represents one of the permissible length specifications for its associated type.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

initial_value
provides an initial value for the entity specified by the immediately preceding name.

+----------------------------End of IBM Extension----------------------------+

initialization_expr
provides an initial value, by mean of an initialization expression, for the entity specified by the immediately preceding name.

+---------------------------------Fortran 95---------------------------------+

=> NULL()
provides the initial value for the pointer object.

+-----------------------------End of Fortran 95------------------------------+

Rules

+---------------------------------Fortran 95---------------------------------+

Within the context of a derived type definition:

If => appears for a variable, the object must have the POINTER attribute.

+-----------------------------End of Fortran 95------------------------------+

If initialization_expr appears for a variable, the object cannot have the POINTER attribute.

Entities in type declaration statements are constrained by the rules of any attributes specified for the entities, as detailed in the corresponding attribute statements.

The type declaration statement overrides the implicit type rules in effect. You can use a type declaration statement that confirms the type of an intrinsic function. The appearance of a generic or specific intrinsic function name in a type declaration statement does not cause the name to lose its intrinsic property.

An object cannot be initialized in a type declaration statement if it is a dummy argument, allocatable object, pointer, function result, object in blank common, integer pointer, external name, intrinsic name, or automatic object. Nor can an object be initialized if it has the AUTOMATIC attribute. The object may be initialized if it appears in a named common block in a block data program unit IBM Extension Begins or if it appears in a named common block in a module. IBM Extension Ends

+---------------------------------Fortran 95---------------------------------+

In Fortran 95, a pointer can be initialized. Pointers can only be initialized by the use of => NULL().

+-----------------------------End of Fortran 95------------------------------+

The specification expression of a type_param_value or an array_spec can be a nonconstant expression if the specification expression appears in an interface body or in the specification part of a subprogram. Any object being declared that uses this nonconstant expression and is not a dummy argument or a pointee is called an automatic object.

An attribute cannot be repeated in a given type declaration statement, nor can an entity be explicitly given the same attribute more than once in a scoping unit.

initialization_expr must be specified if the statement contains the PARAMETER attribute. If the entity you are declaring is a variable, and initialization_expr FORTRAN 95 Begins or NULL() FORTRAN 95 Ends is specified, the variable is initially defined.

+---------------------------------Fortran 95---------------------------------+

If the entity you are declaring is a derived type component, and initialization_expr or NULL() is specified, the derived type has default initialization.

+-----------------------------End of Fortran 95------------------------------+

a becomes defined with the value determined by initialization_expr, in accordance with the rules for intrinsic assignment. If the entity is an array, its shape must be specified either in the type declaration statement or in a previous specification statement in the same scoping unit. A variable or variable subobject cannot be initialized more than once. If a is a variable, the presence of initialization_expr FORTRAN 95 Begins or NULL() FORTRAN 95 Ends implies that a is a saved object, except for an object in a named common block. The initialization of an object could affect the fundamental storage class of an object.

An array_spec specified in an entity_decl takes precedence over the array_spec in the DIMENSION attribute.

An array function result that does not have the ALLOCATABLE or POINTER attribute must have an explicit-shape array specification.

If the entity declared is a function, it must not have an accessible explicit interface unless it is an intrinsic function.

+-------------------------------IBM Extension--------------------------------+

If T or F, defined previously as the name of a constant, appears in a type declaration statement, it is no longer an abbreviated logical constant but the name of the named constant.

+----------------------------End of IBM Extension----------------------------+

The optional comma after char_length in a CHARACTER type declaration statement is permitted only if no double colon separator (::) appears in the statement.

If the CHARACTER type declaration statement is in the scope of a module, block data program unit, or main program, and you specify the length of the entity as an inherited length, the entity must be the name of a named character constant. The character constant assumes the length of its corresponding expression defined by the PARAMETER attribute.

If the CHARACTER type declaration statement is in the scope of a procedure and the length of the entity is inherited, the entity name must be the name of a dummy argument or a named character constant. If the statement is in the scope of an external function, it can also be the function or entry name in a FUNCTION or ENTRY statement in the same program unit. If the entity name is the name of a dummy argument, the dummy argument assumes the length of the associated actual argument for each reference to the procedure. If the entity name is the name of a character constant, the character constant assumes the length of its corresponding expression defined by the PARAMETER attribute. If the entity name is a function or entry name, the entity assumes the length specified in the calling scoping unit.

The length of a character function is either a specification expression (which must be a constant expression if the function type is not declared in an interface block) or it is an asterisk, indicating the length of a dummy procedure name. The length cannot be an asterisk if the function is an internal or module function, if it is recursive, or if it returns array or pointer values.

Examples

      CHARACTER(KIND=1,LEN=6) APPLES /'APPLES'/
      CHARACTER*7, TARGET :: ORANGES = 'ORANGES'
      CALL TEST(APPLES)
      END
 
      SUBROUTINE  TEST(VARBL)
        CHARACTER*(*), OPTIONAL :: VARBL   ! VARBL inherits a length of 6
 
        COMPLEX, DIMENSION (2,3) :: ABC(3) ! ABC has 3 (not 6) array elements
        REAL, POINTER :: XCONST
 
        TYPE PEOPLE                        ! Defining derived type PEOPLE
          INTEGER AGE
          CHARACTER*20 NAME
        END TYPE PEOPLE
        TYPE(PEOPLE) :: SMITH = PEOPLE(25,'John Smith')
      END

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]