Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 3 Data types and data objects

Derived-type definition

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The format of a derived-type definition is:

TYPE [[, access-spec] ::] type-name
   [private-sequence-statement] ...
   component-definition-statement
   [component-definition-statement] ...
END TYPE [type-name]
access-spec

is one of:

  • PRIVATE

  • PUBLIC

type-name

is the name of the type being defined. type-name must not conflict with the intrinsic type names.

private-sequence-statement

is a PRIVATE statement or a SEQUENCE statement.

The use of PRIVATE and PUBLIC is only allowed if the type definition is within a module. Their use is explained in Chapters 7 and 10.

The SEQUENCE statement is explained below.

component-definition-statement

is

type-spec [[component-attr-list]::] component-declaration
component-attr-list

can only contain the DIMENSION and POINTER attributes.

component-declaration

is

component-name [(component-array-spec)][*character-length]

A component array without the POINTER attribute must have an explicit-shape specification with constant bounds.

The presence of the SEQUENCE statement implies that the components of the type will be arranged in storage in the order in which they are defined. The type is then known as a sequence derived type. If all components are of character type it has character sequence type, and if all the components are of numeric type it has numeric sequence type.

Equivalencing variables of derived type which have different sequence types is a supported extension.

If a component is of the same derived type as the type being defined then the component must have the POINTER attribute.

For example, a singly linked list can be created as a set of "nodes", each containing a value and a pointer to the next node. A type node can be defined as follows:

  TYPE node
    INTEGER :: value
    TYPE(node), POINTER :: next
    !  next must have the POINTER
    !  attribute
  END TYPE node

Structure constructor

A structure constructor specifies a scalar value for a derived type by specifying the values for the components in the order that they appear in the definition. For example:

TYPE employee
   CHARACTER(LEN=30) :: surname
   CHARACTER(LEN=20) :: firstname
   INTEGER :: id
END TYPE employee
TYPE(employee) :: programmers(30)
TYPE(employee) :: &
   robjones=employee('Jones','Rob',20)
programmers(1) = employee('Smith','John',34)

employee('Smith','John',34) is a structure constructor that contains the values assigned to the components of the first element of the array programmers by the final statement above.

Note that the name of the type must precede the parenthesized data values of the components, a value must be present for each component, and objects of derived type may be initialized by a structure constructor in a derived-type declaration.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.