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
Nonkeyword Form
The len is a specification expression or an asterisk (*). If no length is specified, the default length is 1.
If the length evaluates to a negative value, the length of the character entity is zero.
The len is a specification expression or an asterisk enclosed in parentheses, or a scalar integer literal constant (with no kind parameter). The comma is permitted only if no double colon (::) appears in the type declaration statement.
This form can also (optionally) be specified following the name of the data object or function (v*len). In this case, the length specified overrides any length following the CHARACTER type specifier.
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.
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: