CHARACTER Statement (Nonexecutable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
CHARACTER Statement (Nonexecutable)
The CHARACTER type specification statement explicitly assigns the
CHARACTER data type to symbolic names, and optionally assigns initial
values to the variables.
Semantics
If an array declarator is specified in a type statement, the declarator
for that array must not appear in any other specification statement (such
as DIMENSION). If only the array name is specified, an array declarator
must appear within a DIMENSION or COMMON statement.
The length specification can be one of the following:
* An unsigned nonzero integer constant.
* An integer constant expression with a positive value. The integer
expression must be enclosed in parentheses and cannot contain
variable names. Example: (-3 + 4).
* An asterisk enclosed in parentheses: (*).
* A variable enclosed in parentheses. This is an extension to the
ANSI 77 standard.
A length specification can be appended to the end of a symbolic name to
designate its length. If the length specification is a variable, it must
be a formal argument to the program unit in which the character type is
declared. The variable must also be an integer type, and it must contain
a positive value. If the length specification is omitted, the length is
assumed to be one.
The CHARACTER*(*) form can be used only for named constants, formal
arguments, function subprograms, or entry names in functions.
NOTE If the symbolic name has an appended length specification, the
specification overrides the length n in the CHARACTER*n
specification. Therefore, CHARACTER*6 q, CHARACTER q*6, and
CHARACTER*10 q*6 are all equivalent. Each reserves space for a
character variable named q of length 6. Also, CHARACTER*(*) name
and CHARACTER name*(*) are equivalent.
Examples Notes
---------------------------------------------------------------------------------------
CHARACTER*5 name(6)*10,zip(6) The variables name and zip are character
arrays with six elements each. Each
element in name has a length of 10. Each
element in zip has a length of 5.
CHARACTER*6 var The variable var is defined as type
CALL sub (var) CHARACTER and as six characters long.
:
SUBROUTINE sub (var1)
CHARACTER*(*) var1 The variable var1 is defined as being of
type CHARACTER and as having the same
length as the variable var in the calling
subroutine.
As an extension to the ANSI 77 standard, you can initialize variables or
arrays in a type specification statement by enclosing the initialization
values between slashes. The following examples illustrate this method of
initialization:
CHARACTER*10 string/'0123456789'/
CHARACTER*25 stringtab(10)*10/10*'THIS IS IT'/,name*4/'BILL'/
See "DATA Statement (Nonexecutable)" for further information on
initialization.
MPE/iX 5.0 Documentation