4.5.2 Character Type Declaration Statements

Character type declaration statements take the following form:

CHARACTER[*len[,]] v[*len] [/clist/] [,v[*len] [/clist/] ] . . .
len
Is an unsigned integer constant, an integer constant expression enclosed in parentheses, or an asterisk (*) enclosed in parentheses. The value of len specifies the length of the character data elements.
v
Is the symbolic name of a constant, variable, array, array declarator, statement function, or function subprogram.
clist
Is a list of constants, as in a DATA statement. If v is the symbolic name of a constant, the clist must not be present.

Rules and Behavior

If you use the form CHARACTER*len, len is the default length specification for that list. If an item in that list does not have a length specification, the item's length is len. However, if an item does have a length specification, it overrides the default length specified in CHARACTER*len.

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 the symbolic name of a 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:')

On OpenVMS systems, the length specification must range from 1 to 65535; on Tru64 UNIX systems, 1 to 2**31-1. If there is no length specification, a length of 1 is assumed.

Character type declaration statements can define arrays if they include array declarators in their list. The array declarator goes first if both an array declarator and a length are specified.

A character type declaration statement can assign initial values to variables or arrays if it specifies a list of constants (the clist). The specified constants initialize only the variable or array that immediately precedes them. The clist cannot have more than one element unless it initializes an array. When the clist initializes an array, it must contain a value for every element in the array.

Examples

The following examples show valid and invalid character type declaration statements:

Valid

The first example specifies an array, NAMES, with 100 32-character elements; an array, SOCSEC, with 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'/

In the next example, the CHARACTER statement specifies two 8- character variables, LAST and FIRST.

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

In the next example, the CHARACTER statement specifies an array, LETTER, with twenty-six 1-character elements. It also specifies a dummy argument, BUBBLE, that has a passed length defined by the calling program.

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

Invalid

The following CHARACTER statement is invalid because the length specified for BIGCHR is too large and the length specifier for QUEST is not an integer constant expression:

CHARACTER*16 BIGCHR*(60000*60000), QUEST*(5*INT(A))

For More Information:


Previous Page Next Page Table of Contents