Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
E77790.pdf
Скачиваний:
2
Добавлен:
16.05.2024
Размер:
1.29 Mб
Скачать

4.5 Unsigned Integers

As with the legacy f77 compiler, a POINTER statement cannot be used as a field declaration.

f95 also allows:

Either ”.” or ”%”T can be used as a structure field dereference symbol:struct.field or struct%field.

Structures can appear in a formatted I/O statement.

Structures can be initialized in a PARAMETER statement; the format is the same as a derived type initialization.

Structures can appear as components in a derived type, but the derived type must be declared with the SEQUENCE attribute.

4.5Unsigned Integers

The Fortran compiler accepts a new data type, UNSIGNED, as an extension to the language. Four KIND parameter values are accepted with UNSIGNED: 1, 2, 4, and 8, corresponding to 1-, 2-, 4-, and 8-byte unsigned integers, respectively.

The form of an unsigned integer constant is a digit-string followed by the upper or lower case letter U, optionally followed by an underscore and kind parameter. The following examples show the maximum values for unsigned integer constants:

255u_1

65535u_2

4294967295U_4

18446744073709551615U_8

Expressed without a kind parameter (12345U), the default is the same as for default integer. This is U_4 but can be changed by the -xtypemap option, which will change the kind type for default unsigned integers.

Declare an unsigned integer variable or array with the UNSIGNED type specifier:

UNSIGNED U

UNSIGNED(KIND=2) :: A

UNSIGNED*8 :: B

4.5.1Arithmetic Expressions

Binary operations, such as + - * / cannot mix signed and unsigned operands. That is, U*N is illegal if U is declared UNSIGNED, and N is a signed INTEGER.

Chapter 4 • Oracle Developer Studio Fortran Features and Extensions

179

4.5 Unsigned Integers

Use the UNSIGNED intrinsic function to combine mixed operands in a binary operation, as in U*UNSIGNED(N)

An exception is when one operand is an unsigned integer and the other is a signed integer constant expression with positive or zero value; the result is an unsigned integer.

The kind of the result of such a mixed expression is the largest kind of the operands.

Exponentiation of a signed value is signed while exponentiation of an unsigned value is unsigned.

Unary minus of an unsigned value is unsigned.

Unsigned operands may mix freely with real, complex operands.

4.5.2Relational Expressions

Signed and unsigned integer operands may be compared using intrinsic relational operations. The result is based on the unaltered value of the operands.

4.5.3Control Constructs

The CASE construct accepts unsigned integers as case-expressions.

Unsigned integers are not permitted as DO loop control variables, or in arithmetic IF control expressions.

4.5.4Input/Output Constructs

Unsigned integers can be read and written using the I, B, O, and Z edit descriptors.

They can also be read and written using list-directed and namelist I/O. The written form of an unsigned integer under list-directed or namelist I/O is the same as is used for positive signed integers.

Unsigned integers can also be read or written using unformatted I/O.

4.5.5Intrinsic Functions

Unsigned integers are allowed in intrinsic functions, except for SIGN and ABS.

A new intrinsic function, UNSIGNED, is analogous to INT but produces a result of unsigned type. The form is

180 Oracle Developer Studio 12.6: Fortran User's Guide • July 2017

Соседние файлы в предмете Информационные и сетевые технологии