• Aucun résultat trouvé

TYPE SPECIFICATION

Dans le document CRAY® COMPUTER SYSTEMS (Page 101-104)

DATA TYPES 3

3.1 TYPE SPECIFICATION

A data type (for a symbolic constant, variable, array, external function, or statement function) can be specified explicitly in a type statement or implicitly by the first letter of its symbolic name. If no type is

specified, a first letter of I, J, K, L, M, or N implies type integer; any other first letter implies type real. The default for implied typing can be changed or confirmed by an IMPLICIT statement.

After a symbolic name is identified with a type, that type applies to all uses of that name. Exception: a common block can have the same name as a variable or array, but the common block name has no type.

The data type of an array element is the same as the data type of the array that contains it.

A function's data type must, in effect, be specified twice; the two specifications must agree for the function's result to be valid. The specifications are as follows:

• The type of the function's result value is determined in the coding of the function (see 2.4.2.1, 2.4.3.1, and 2.5.1.2).

• The type of the function reference in the calling program unit is specified in the same way as a variable's type; the type is either implicit in its name or declared within the same program unit (see 2.4.1 and 2.4.1.1).

3.1.1 TYPE STATEMENTS

A type statement declares the type of an entity, thereby either overriding or confirming the entity's implicit type, and can specify array dimensions by including array declarators with array names.

The appearance of a symbolic name (of a constant, variable, array, or function) in a type statement specifies the data type for all appearances of that name in the program unit. A name's type must not be explicitly specified more than once within a program unit.

The name of a subroutine, main program, or block data subprogram must not appear in a type statement.

If a specific intrinsic function name appears in a type statement that conflicts with that function'S type (as specified in appendix B), and the name is used as an intrinsic function name, the conflicting type statement is ignored and a warning message is issued. Note the requirements for function typing in the 3.1 introduction preceding.

The form of type statements other than POINTER and CHARACTER is as follows:

type v[,v] ••.

type

v

Specifies type INTEGER, REAL, DOUBLE PRECISION, COMPLEX, or LOGICAL. (CHARACTER and POINTER type statements have

different requirements; see 3.7.1 and 3.9.1. Boolean type does not have a type statement.)

Symbolic name of a constant, variable name, array name, function name, dummy procedure name, or array declarator.

An array declarator includes dimension declarators (see 4.3.4).

Examples:

INTEGER NPAK(60,230),RTEST,XREF(20,2),ARRAY DOUBLE PRECISION ANG(1014,8),KLIM,PTEST(10) COMPLEX IMAG,COMARR(30,3),ZREF,KITEMS(64) LOGICAL KEY2,BOOLSET(64,64),TTABLEB(2,20,15)

In the above examples, numbers in parentheses are dimension

declarators, and the names preceding the parentheses are array names.

Other names can represent entities as listed in the preceding format description. See E.5 for extensions of the type declaration

statements.

3.1.2 IMPLICIT STATEMENT

An IMPLICIT statement changes or confirms the data typing of constants, variables, arrays, and functions according to the first letter of their symbolic names.

type

a

Data type: INTEGER, REAL, DOUBLE PRECISION, COMPLEX, CHARACTER[*len], or LOGICAL

len Length of the character entities. len can be an unsigned, nonzero, positive integer constant or expression; maximum values are shown in 3.7.

Letter; a range of letters within the alphabet can be written in the form afirst-alast; for example, I-M.

An IMPLICIT statement specifies a type for names of constants, variables, arrays, and functions (except intrinsic functions), beginning with any letter appearing singly or within a range in the specification. IMPLICIT statements do not change the types of intrinsic functions. An IMPLICIT statement applies only to the program unit containing it.

The appearance of a constant, variable, array, or function name in a type statement overrides or confirms type specification by an IMPLICIT

statement. An explicit type specification in a FUNCTION statement overrides IMPLICIT statement typing for the name of that function subprogram.

Within the specification statements of a program unit, IMPLICIT statements must precede all specification statements other than PARAMETER

statements. An IMPLICIT statement must precede a PARAMETER statement to affect the typing of constants named in the PARAMETER statement.

A letter can be specified (or implied within a range of letters) only once in all of the IMPLICIT statements in a program unit.

Examples:

IMPLICIT LOGICAL(L)

IMPLICIT DOUBLE PRECISION(X,Y),COMPLEX(C) IMPLICIT INTEGER(A,B,F-K),REAL(M-W,Z)

The last example declares variables starting with A, B, F, G, H, I, J,

and K to be integer type, and variables starting with M, N, 0, P, Q, R, S, T, Uj V, W, and Z to be real type.

3.1.3 IMPLICIT NONE STATEMENT (CFT77 EXTENSION)

The IMPLICIT NONE statement prevents the use of implicit typing by requiring all constant, variable, array, dummy argument, statement

function, and function (except intrinsic function) names to appear in an explicit type statement. It also requires all nonintrinsic subroutine and function names to appear in an EXTERNAL statement. The statement consists of the words IMPLICIT NONE with no other parameters.

The IMPLICIT NONE statement applies only to the program unit containing it and must be the first specification statement.

When IMPLICIT NONE is specified, failure to provide type or EXTERNAL declarations is a fatal error for the cases already described. Intrinsic subroutine and function names need not appear in explicit type statements and must not be declared EXTERNAL.

Dans le document CRAY® COMPUTER SYSTEMS (Page 101-104)