5.1.2 Declaration Statements for Character Types

A CHARACTER type specifier can be immediately followed by the length of the character object or function. It takes one of the following forms:

Keyword Forms

CHARACTER [([LEN=]len)]
CHARACTER [([LEN=]len [, [KIND=]n])]
CHARACTER [(KIND=n [, LEN=len])]

Nonkeyword Form

CHARACTER*len[,]

len
Is one of the following:

The largest valid value for len in both forms is 2147483647 (2**31-1) on Tru64 UNIX, Linux, and Windows systems; 65535 on OpenVMS systems. Negative values are treated as zero.

n
Is a scalar integer initialization expression specifying a valid kind parameter. Currently the only kind available is 1.

Rules and Behavior

An automatic object can appear in a character declaration. The object cannot be a dummy argument, and its length must be declared with a specification expression that is not a constant expression.

The length specified for a character-valued statement function or statement function dummy argument of type character must be an integer constant expression.

When an asterisk length specification *(*) is used for a function name or dummy argument, it assumes the length of the corresponding function reference or actual argument. Similarly, when an asterisk length specification is used for a named constant, the name assumes the length of the actual constant it represents. For example, STRING assumes a 9-byte length in the following statements:

  CHARACTER*(*) STRING
  PARAMETER (STRING = 'VALUE IS:')

A function name must not be declared with a * length if the function is an internal or module function, or if it is array-valued, pointer-valued, recursive, or pure.

The form CHARACTER*(*) is an obsolescent feature in Fortran 95.

Examples

The following example declares an array NAMES containing 100 32-character elements, an array SOCSEC containing 100 9-character elements, and a variable NAMETY that is 10 characters long and has an initial value of 'ABCDEFGHIJ'.

  CHARACTER*32 NAMES(100),SOCSEC(100)*9,NAMETY*10 /'ABCDEFGHIJ'/

The following example includes a CHARACTER statement declaring two 8-character variables, LAST and FIRST.

  INTEGER, PARAMETER :: LENGTH=4
  CHARACTER*(4+LENGTH) LAST, FIRST

The following example shows a CHARACTER statement declaring an array LETTER containing 26 one-character elements. It also declares a dummy argument BUBBLE that has a passed length defined by the calling program.

  SUBROUTINE S1(BUBBLE)
  CHARACTER LETTER(26), BUBBLE*(*)

In the following example, NAME2 is an automatic object:

  SUBROUTINE AUTO_NAME(NAME1)
    CHARACTER(LEN = *)          NAME1
    CHARACTER(LEN = LEN(NAME1)) NAME2

For More Information:


Previous Page Next Page Table of Contents