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 Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

CHARACTER

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Declares entities of type character.

Syntax

CHARACTER [char-selector] [[, attrib-list] ::] entity-list
char-selector

specifies the length and kind of the character variable. It takes one of the following forms:

  • ([LEN=]len-spec[, KIND=kind-param])

  • (len-spec, [KIND=]kind-param)

  • (KIND=kind-param[, LEN=len-spec])

  • *len-const [,]

  • *(len-spec[) ,]

where kind-param (if specified) must be 1, the default; len-spec is either an asterisk (*) or a specification expression; and len-const is an integer constant. In the last form, len-param is enclosed in parentheses, and the optional comma may be included only if the double colon does not appear in the type declaration statement. If len-spec evaluates to a negative value, a zero-length string is declared. If len-spec is unspecified, the default is 1.

attrib-list

is a list of one or more of the following attributes, separated by commas:

Table 10-4 Title not available (CHARACTER)

ALLOCATABLE

INTRINSIC

PRIVATE

DIMENSION

OPTIONAL

PUBLIC

EXTERNAL

PARAMETER

SAVE

INTENT

POINTER

TARGET

 

If attrib-list is present, it must be followed by the double colon. For information about individual attributes, see the corresponding statement in this chapter.

entity-list

is a list of entities, separated by commas. Each entity takes the form:

name[(array-spec)][*len-spec][= initialization-expr]

where name is the name of a variable or function, array-spec is a comma-separated list of dimension bounds, len-spec is either an asterisk (*) or a specification expression, and initialization-expr is a character constant expression. If initialization-expr is present, entity-list must be preceded by the double colon.

Description

The CHARACTER statement is used to declare the length and properties of character data. It is constrained by the rules for all type declaration statements, including the requirement that it precede all executable statements.

To indicate that the length of a character can vary, you may use an assumed character length parameter by specifying an asterisk (*) for len-param. The asterisk may be used only when doing the following:

  • Declaring the type of a function. The function must not be an internal or module function, nor must it be array-valued, pointer-valued, or recursive.

  • Declaring a dummy argument of a procedure.

  • Declaring a named constant (see the PARAMETER statement).

Examples

The following are valid declarations:

CHARACTER c1, c2
CHARACTER(LEN=80) :: text(0:25)
CHARACTER(2, 1), PARAMETER :: limit='ZZ'
! initialize an array, using an array constructor
CHARACTER(4) :: response(3) = (/"Yes.", "No!!", "Huh?"/)
! use slashes as initialization delimiters, an HP extension
CHARACTER*10 c1/'Tom'/,c2/'Jones'/ ! note, no double colon

The following are valid uses of the assumed length parameter:

CHARACTER(*) dummy_arg_name
CHARACTER(*), PARAMETER :: hello=”Hi Sam”
CHARACTER(LEN=*), PARAMETER :: hello=”Hi Sam”

Assuming that c is an ordinary variable and not the dummy argument to a procedure, the following declaration is an illegal use of the assumed length parameter:

CHARACTER*(*) c  ! illegal

Related concepts

For related information, see the following:

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