FORTRAN 77 Language Reference

Description

The value can be a constant or the result of an expression. The kinds of assignment statements: are arithmetic, logical, character, and record assignments.

Arithmetic Assignment

v is of numeric type and is the name of a variable, array element, or record field.

e is an arithmetic expression, a character constant, or a logical expression. Assigning logicals to numerics is nonstandard, and may not be portable; the resultant data type is, of course, the data type of v. @

Execution of an arithmetic assignment statement causes the evaluation of the expression e, and conversion to the type of v (if types differ), and assignment of v with the resulting value typed according to the following table.

Type of v

Type of e

INTEGER*2, INTEGER*4, or INTEGER*8

REAL

REAL*8

REAL*16 (SPARC only)

DOUBLE PRECISION

COMPLEX*8

COMPLEX*16

COMPLEX*32 (SPARC only)

INT(e)

REAL(e)

REAL*8

QREAL(e) (SPARC only)

DBLE(e)

CMPLX(e)

DCMPLX(e)

QCMPLX(e) (SPARC only)


Note -

Compiling with any of the options -i2, -dbl, -r8, or -xtypemap can alter the default data size of variables and expressions. This is discussed in Chapter 2. See also the Fortran User's Guide for a description of these options.


Example: An assignment statement:


       REAL A, B 
       DOUBLE PRECISION V 
       V = A * B 

The above code is compiled exactly as if it were the following:


       REAL A, B 
       DOUBLE PRECISION V 
       V = DBLE( A * B )

Logical Assignment

v is the name of a variable, array element, or record field of type logical.

e is a logical expression, or an integer between -128 and 127, or a single character constant.

Execution of a logical assignment statement causes evaluation of the logical expression e and assignment of the resulting value to v. If e is a logical expression (rather than an integer between -128 and 127, or a single character constant), then e must have a value of either true or false.

Logical expressions of any size can be assigned to logical variables of any size. The section on the LOGICAL statement provides more details on the size of logical variables.

Character Assignment

The constant can be a Hollerith constant or a string of characters delimited by apostrophes (') or quotes ("). The character string cannot include the control characters Control-A, Control-B, or Control-C; that is, you cannot hold down the Control key and press the A, B, or C keys. If you need those control characters, use the char() function.

If you use quotes to delimit a character constant, then you cannot compile with the -xl option, because, in that case, a quote introduces an octal constant. The characters are transferred to the variables without any conversion of data, and may not be portable.

Character expressions which include the // operator can be assigned only to items of type CHARACTER. Here, the v is the name of a variable, substring, array element, or record field of type CHARACTER; e is a character expression.

Execution of a character assignment statement causes evaluation of the character expression and assignment of the resulting value to v. If the length of e is more than that of v, characters on the right are truncated. If the length of e is less than that of v, blank characters are padded on the right.

Record Assignment

v and e are each a record or record field. @

The e and v must have the same structure. They have the same structure if any of the following occur:

The sections on the RECORD and STRUCTURE statements have more details on the structure of records.