| Fortran Language Reference Manual, Volume 1 - S-3692-51 | ||
|---|---|---|
| Prev Section | Chapter 4. Data Types | Next Section |
The default real kind, default integer kind, and default logical kind are all stored in one storage unit. Default complex (which is really two default reals) and double-precision real data is stored in two storage units.
Note: This chapter describes each of the intrinsic types. The descriptions include a simple statement form to show how objects of these types can be declared. These simple forms are not complete. If they are used to construct statements, the statements will be correct, but other variations are permitted. Section 5.1, contains the complete formats. The kind parameter that appears in the formats is limited to a scalar integer initialization expression, which is described in Section 7.2.9.2.
The name of the integer type is INTEGER. The following format shows how integer objects can be declared:
INTEGER [ ([ KIND = ] kind_param) ] [ [ , attribute_list ] :: ] entity_list |
Examples:
INTEGER :: X INTEGER :: COUNT, K, TEMPORARY_COUNT INTEGER(SHORT) :: PARTS INTEGER, DIMENSION(0:9) :: SELECTORS, IX |
The integer data type has values that represent a subset of the mathematical integers. The intrinsic inquiry function RANGE provides the decimal exponent range for integers of the kind of its argument. Only one kind of integer is required by the standard, but the Cray Fortran Compiler supports several. Values that overflow in storage may be truncated.
If kind_param is specified, it must have one of the values that is shown in Table 4-1. The default kind_param is specific to your hardware platform. Options given to the Cray Fortran command allow you to change the size and storage aspects of integer values. See the Cray Fortran Compiler Commands and Directives Reference Manualfor information on changing default kind parameter values.
Table 4-1. Integer Kind Values
kind_param | Value range | Size / Storage (-dh, default) | Size / Storage (-eh)[1] option enabled |
|---|---|---|---|
1 | -27 < n < 27 | 8 bits / 32 bits | 8 bits / 8 bits |
2 | -215 < n < 215 | 16 bits / 32 bits | 16 bits / 16 bits |
4 | -231 < n < 231 | 32 bits / 32 bits | 32 bits / 32 bits |
8 | -263 < n < 263 | 64 bits / 64 bits | 64 bits / 64 bits |
The following table shows power-of-10 values that approximate the power-of-2 values shown in Table 4-2.
Note: The Size information in the following table refers to the size according to the integer model defined on the MODELS(3i) man page.
The RANGE(3i) intrinsic function returns the decimal exponent range of a given number. For more information on this intrinsic function, see the RANGE(3i) man page.
The KIND(3i) intrinsic function can be used to determine the kind parameter of its integer argument.
The SELECTED_INT_KIND(3i) intrinsic function returns the integer kind parameter required to represent as many decimal digits as are specified by the function argument. If there is no such integer type available on your system, -1 is returned.
The following statement declares I and J to be integer objects with a representation method that permits at least five decimal digits; (that is, it includes all integers between -105 and 105 as follows):
INTEGER (SELECTED_INT_KIND (5)) I, J |
There are both binary and unary intrinsic operators for the integer type. Binary operators have two operands and unary operators have only one. The binary arithmetic operations for the integer type are: +, -, *, /, and **. The unary arithmetic operations are + and -. The relational operations (all binary) are: .LT., <, .LE., <=, .EQ., ==, .NE., /=, .GE., >=, .GT., and >. The result of an intrinsic arithmetic operation on integer operands is an integer entity. The result of an intrinsic relational operation is a logical entity of default logical kind.
An integer constant is a string of decimal digits, optionally preceded by a sign, and optionally followed by an underscore and a kind parameter. An integer constant that must not have a kind type parameter is defined as follows:
The format of a signed integer literal constant (which may have a kind type parameter) is defined as follows:
Table 4-4.
| signed_int_literal_constant | is |
| |
| int_literal_constant | is |
| |
| kind_param | is |
| |
|
| or |
| |
| sign | is |
| |
|
| or |
|
The signed integer literal constant often takes the following format:
[ sign ] digit_string [ _ kind_param ] |
In the following examples, assume that LONG and SHORT are named constants with values that are valid integer kind parameters:
42 9999999999999999999999_LONG +64 10000000 -258_SHORT |
Integer constants are interpreted as decimal values. However, in a DATA statement, it is possible to initialize an object with a value that is presented as if it had a nondecimal base. The allowed forms are unsigned binary, octal, and hexadecimal constants, and are defined as follows:
The Cray Fortran Compiler supports binary, octal, and hexadecimal constants in other contexts; for more information on these forms see Section 4.3.6.
A binary_constant is defined as follows:
You must specify 0 or 1 for digit.
An octal_constant is defined as follows:
You must specify a value from 0 through 7 for digit.
A hex_constant is defined as follows:
Table 4-8.
| hex_constant | is |
| |
|
| or |
| |
| hex_digit | is |
| |
|
| or |
| |
|
| or |
| |
|
| or |
| |
|
| or |
| |
|
| or |
| |
|
| or |
|
You must specify a value from 0 through 9 or one of the letters A through F (representing the decimal values 10 through 15) for digit. The Cray Fortran Compiler supports lowercase letters, so the hexadecimal digits A through F can be represented by their lowercase equivalents, a through f.
In these constants, the binary, octal, and hexadecimal digits are interpreted according to their respective number systems. For example, all of the following have a value equal to the decimal value 10:
B"1010" O'12' Z"A" |
The name of the real data type is REAL. The name DOUBLE PRECISION is used for another kind of the real type. You can use one of the following formats to declare objects of real type:
|
Examples:
REAL X, Y REAL(KIND = HIGH), SAVE :: XY(10, 10) REAL, POINTER :: A, B, C DOUBLE PRECISION DD, DXY, D |
The values of the real data type approximate the mathematical real numbers. The set of values varies from processor to processor. The Fortran standard requires a processor to support at least two approximation methods for the real type. The Cray Fortran Compiler provides two or three, depending on your platform, so there is more than one kind value for the real type.
If kind_param is specified, it must have one of these values: 4, 8, or 16. The default kind_param and the values associated with the kind values are specific to your hardware platform. These values are shown in Table 4-9. Options given to the Cray Fortran command allow you to change the size and storage aspects of real values. See the Cray Fortran Compiler Commands and Directives Reference Manual for information on changing default kind parameter values.
Table 4-9. Real and Complex Kind Values
kind_param | Value range | Size and storage for reals | Size and storage for complex |
|---|---|---|---|
4 (default) | 2 -125 < n < 2 128 | 32 bits | 64 bits (each part is 32 bits) |
8 | 2 -1021 < n < 2 1024 | 64 bits | 128 bits (each part is 64 bits) |
16 | 2 -16381 < n < 2 16384 | 128 bits | 256 bits (each part is 128 bits) |
The following table shows power-of-10 values that approximate some of the power-of-2 values shown in Table 4-10.
The KIND(3i) intrinsic function can be used to determine the kind parameter of its real argument. The intrinsic functions PRECISION(3i) and RANGE(3i) return the decimal precision and exponent range of the approximation method used for the kind of the argument. The intrinsic function SELECTED_REAL_KIND(3i) returns the kind value required to represent as many digits of precision as specified by the first argument and the decimal range specified by the optional second argument.
The following statement declares X to have at least five decimal digits of precision and no specified minimum range:
REAL(SELECTED_REAL_KIND(5)) X |
The following statement declares Y to have at least eight decimal digits of precision and a range that includes values between 10-70 and 1070 in magnitude:
REAL(SELECTED_REAL_KIND(8, 70)) Y |
The intrinsic binary arithmetic operators for the real type are: +, -, *, /, and **. The intrinsic unary arithmetic operators are: + and -. The relational operators are: .LT., <, .LE., <=, .EQ., ==, .NE., /=, .GE., >=, .GT., >, .LG., and <>. The result of an intrinsic arithmetic operation on real operands is a real entity. If one of the operands of an arithmetic operation is an integer entity, the result is still a real entity. The result of an intrinsic relational operation is a logical entity of default logical kind.
Note: The Fortran standard does not describe the .LG. or <> operators.
A real constant is distinguished from an integer constant by containing either a decimal point, an exponent, or both. The format for a signed_real_literal_constant is defined as follows:
Table 4-11.
| signed_real_literal_constant | is |
| |
| real_literal_constant | is | significand exponent_letter exponent [ _kind_param] | |
|
| or | digit_string exponent_letter exponent [ _kind_param ] | |
| significand | is |
| |
|
| or |
| |
| exponent_letter | is |
| |
|
| or |
| |
| exponent | is |
|
A signed real literal constant can take one of the following forms:
|
For whole_part, specify a digit_string. For fraction_part, specify a digit_string. For exponent, specify a signed_digit_string.
If both a kind_param and an exponent_letter are present, the exponent_letter must be E or e. If a kind_param is present, the real constant is of that kind; if a D or d exponent letter is present, the constant is of type double-precision real; otherwise, the constant is of type default real.
On UNICOS/mp systems, if you have disabled double-precision arithmetic by specifying -dp on the Cray Fortran command line, D is treated as E.
A real constant can have more decimal digits than will be used to approximate the real number.
Examples of signed real literal constants are as follows:
-14.78 +1.6E3 2.1 -16.E4_HIGH 0.45_LOW .123 3E4 2.718281828459045D0 |
In the preceding example, the parameters HIGH and LOW must have been defined, and their values must be kind parameters for the real data type permitted by the Cray Fortran Compiler.
If a real literal constant has a kind parameter, it takes precedence over an exponent letter. Consider the following specification:
1.6E4_HIGH |
The example's code fragment will be represented by the method specified for HIGH, even though 1.6E4 would be represented by a different method.
The name of the complex type is COMPLEX. A format for declaring objects of this type is as follows:
COMPLEX [([ KIND = ] kind_param) ] [[ , attribute_list ] :: ] entity_list |
COMPLEX CC, DD COMPLEX(KIND = single), POINTER :: CTEMP(:) |
The complex data type has values that approximate the mathematical complex numbers. A complex value is a pair of real values; the first is called the real part and the second is called the imaginary part. Each approximation method used to represent data entities of type real is available for entities of type complex with the same kind parameter values.
When a complex entity is declared with a kind specification, this kind is used for both parts of the complex entity. There is no special double-precision complex declaration, as such. If no kind parameter is specified, the entity is of type default complex which corresponds to default real. The SELECTED_REAL_KIND(3i) intrinsic function may be used in a declaration of a complex object.
If kind_param is specified, it must have one of these values: 4, 8, or 16. The default kind is specific to your hardware platform. The values, the ranges (for both the real and imaginary portions of the number), and the defaults supported are the same as those for type real, and these values are shown in Table 4-9. See the Cray Fortran Compiler Commands and Directives Reference Manual for information on changing default kind parameter values.
Table 4-12. Complex Kind Values
kind_param | Value range | Size and storage |
|---|---|---|
4 (default) | 2 -125 < n < 2 128 | 64 bits (each part is 32 bits) |
8 | 2 -1021 < n < 2 1024 | 128 bits (each part is 64 bits) |
16 | 2 -16381 < n < 2 16384 | 256 bits (each part is 128 bits) |
For information on power-of-10 and power-of-2 equivalent values, see Table 4-10.
In the following statement, CX must be represented by an approximation method with at least 8 decimal digits of precision and at least a decimal exponent range between 10-70 and 1070 in magnitude for the real and imaginary parts:
COMPLEX(SELECTED_REAL_KIND(8, 70)) CX |
The intrinsic binary arithmetic operators for the complex type are: +, -, *, /, and **. The intrinsic unary arithmetic operators are: + and -. The intrinsic relational operators are: .EQ., ==, .NE., and /=. The arithmetic operators specify complex arithmetic; the relational operators compare operands to produce default logical results. The result of an intrinsic arithmetic operation on complex operands is a complex entity. If one of the operands is an integer or real entity, the result is still a complex entity.
A complex literal constant is written as two literal constants that are real or integer, separated by a comma, and enclosed in parentheses, as follows:
(real_part , imag_part) |
The Cray Fortran Compiler allows the real and imaginary portions of a complex literal constant to be named constants.
Note: The Fortran standard does not specify the use of named constants as the real or imaginary components of a complex literal constant.
The format for a complex_literal_constant is defined as follows:
Table 4-13.
| complex_literal_constant | is |
| |
| real_part | is |
| |
|
| or |
| |
| imag_part | is |
| |
|
| or |
|
Examples:
(3.0, -3.0) (6, -7.6E9) (3.0_HIGH, 1.6E9_LOW) |
A real kind parameter can be specified for either one of the two real values. If a different real kind parameter is given for each of the two real values, the complex value will have the kind parameter that specifies the greater precision, unless the kind parameters specify the same precision. If both parts are integer, each part is converted to default real. If one part is of integer type and the other is of real type, the integer value is converted to the kind and type of the real value.
The name of the logical type is LOGICAL. A format for declaring objects to be of this type is as follows:
LOGICAL [([ KIND = ] kind_param) ] [[ , attribute_list ] :: ] entity_list |
Examples:
LOGICAL IR, XT LOGICAL(KIND = SMALL), SAVE :: XMASK (3000) |
The logical data type has two values that represent true and false. The Fortran standard requires processors to provide one logical kind, but the Cray Fortran Compiler provides other kinds. Each default logical item occupies one word. (An object of default logical type must occupy the same unit of storage as an object of default real type.) The KIND(3i) intrinsic function can be used to determine the kind number of its argument. There is no intrinsic function analogous to the functions SELECTED_INT_KIND(3i) and SELECTED_REAL_KIND(3i).
If specifying a kind_param, it must have one of the values that is shown in the following table. The default kind_param and the values associated with the kind values are specific to your hardware platform. See the Cray Fortran Compiler Commands and Directives Reference Manual for information on changing default kind parameter values.
Table 4-14.
kind_param | Size / Storage with the -dh option enabled (default) | Size / Storage with the -eh[2] option enabled |
|---|---|---|
1 | 8 bits / 32 bits | 8 bits / 8 bits |
2 | 16 bits / 32 bits | 16 bits / 16 bits |
4 (default) | 32 bits / 32 bits | 32 bits / 32 bits |
8 | 64 bits / 64 bits | 64 bits / 64 bits |
The intrinsic binary operators for the logical type are as follows: conjunction (.AND.), inclusive disjunction (.OR.), logical equivalence (.EQV.), and logical nonequivalence (.NEQV.). The intrinsic unary operation is negation (.NOT.). The exclusive disjunction operator for the Cray Fortran Compiler is .XOR.
Note: The Fortran standard does not specify the .XOR. exclusive disjunction operator.
There are only two logical literal constants. They can be followed by an underscore and a kind parameter. The format for a logical_literal_constant is defined as follows:
If a kind_param is not specified, the type of the constant is default logical. Examples are as follows:
FALSE. TRUE._WORD |
If .T. and .F. are not defined operators in a compilation unit, the Cray Fortran Compiler recognizes .T. as an abbreviation for .TRUE. and .F. for .FALSE.
Note: The Fortran standard does not specify the use of .T. or .F..
The name of the character type is CHARACTER. Declarations for objects of this type may take several different forms. One of these forms is as follows:
CHARACTER [ ([ LEN = ] length_parameter [, [ KIND = ] kind_param ]) ] [ [ , attribute_list ] :: ] entity_list |
The length_parameter can be an asterisk (*) or a specification expression, which is described in Section 7.2.9.3. The various forms of the CHARACTER statement are described in Section 5.1.6, but the following examples use the form specified previously:
CHARACTER(80) LINE CHARACTER(*) GREETING CHARACTER(LEN = 30, KIND = ASCII), DIMENSION(10) :: C1 |
The character data type has a set of values composed of character strings. A character string is a sequence of characters, numbered from left to right 1, 2, ..., n, where n is the length of (number of characters in) the string. Both length and kind are type parameters for the character type. If no length parameter is specified, the length is 1. A character string can have length 0. The maximum length permitted for character strings is 2, 097, 151. Although the Fortran standard permits a processor to provide more than one character kind, the Cray Fortran Compiler supports only one, ASCII. Thus, the Cray Fortran Compiler does not support any nondefault character kinds. If kind_param is specified, it must have the value 1.
The Fortran standard specifies only a partial collating sequence because it is concerned only that operations that compare character objects containing only characters from the Fortran character set will be portable across different processors. Because the Cray Fortran Compiler supports the ASCII character set, it follows the Fortran standard's collating requirements. The intrinsic functions ACHAR(3i) and IACHAR(3i) convert between numeric values and ASCII characters. The intrinsic functions LGT(3i), LGE(3i), LLE(3i), and LLT(3i) provide comparisons between strings based on the ASCII collating sequence.
The binary operation concatenation (//) is the only intrinsic operation on character entities and has a character entity as a result. A number of intrinsic functions are provided that perform character operations. These are described in the Fortran Language Reference Manual, Volume 2. The intrinsic relational operators on objects of type character are .LT., <, .LE., <=, .EQ., ==, .NE., /=, .GE., >=, .GT., and >. The relational operations can be used to compare character entities, but because of possible processor-dependent collating sequences, care must be taken if the results are intended to be portable.
A character literal constant is written as a sequence of characters, enclosed either by apostrophes or quotation marks. The format for a char_literal_constant is as follows:
Table 4-16.
| char_literal_constant | is |
| |
|
| or |
|
Note that, unlike the other intrinsic types, the kind parameter for the character literal constant precedes the constant.
If the string delimiter character (either an apostrophe or a quotation mark) is required as part of the constant, two consecutive such characters with no intervening blanks serve to represent a single such character in the string, for example:
"DON'T" 'DON''T' |
These two examples have the value DON'T. A zero-length character constant can be written as "" or ''. The quotation marks or apostrophes are immediately adjacent to each other.
A Boolean constant represents the literal constant of a single storage unit. There are no Boolean variables or arrays, and there is no Boolean type statement.
Note: The Fortran standard does not describe Boolean values.
A bitwise logical (masking) expression has a Boolean result, with each of its bits representing the result of one or more logical operations on the corresponding bit of the expression's operands.
When an operand of a binary arithmetic or relational operator is Boolean, the operation is performed as if the Boolean operand has the same type as the other operand (that is, no data conversion occurs). If both operands are of type Boolean, the operation is performed as if they were of type integer.
No user-specified or intrinsic functions generate a Boolean result, but some nonstandard intrinsic functions generate Boolean results.
Boolean and logical types differ in the following ways:
Variables, arrays, and functions can be of logical type, and there is a LOGICAL type statement.
A logical variable or constant represents only one value of true or false (rather than separate bit values), and a logical expression yields one true or false value.
Logical entities are invalid in arithmetic, relational, or bitwise logical expressions, while Boolean entities are valid. (Note, however, that results of relational expressions are logical.)
A Boolean constant can be written as an octal, hexadecimal, or Hollerith value. There is no form for binary digits. Boolean constants can represent up to 256 bits of data. This size limit corresponds to the size of the largest numeric type, COMPLEX(KIND = 16). The ultimate size and make-up of the constant is dependent on its context. The constant is truncated or padded to match the size of the type implied by its context. These forms use the notation described in the following sections.
The octal form contains 1 to 86 digits (0 through 7) in either of the following two forms:
It can be a string of digits followed by the letter B or b, as in 177B.
It can be a quoted string of digits followed by the letter O or o, as in "177"O.
It can be a quoted string of digits preceded by the letter O or o, as in O"177".
The 86 digits in a Boolean value correspond to the internal representation of four 64-bit words or eight 32-bit words. If all 86 digits are specified, the left-most octal digit must be only 0 or 1, representing the content of the left-most bit position (bit 0 in the first word) of the value. Each successive octal digit specifies the contents of the next three bit positions. The last octal digit specifies the content of the rightmost three bit positions, which are bits 61, 62, and 63 of the last (fourth or eighth) word. Blanks are ignored in fixed source form. Blanks are significant in free source form for the dddB syntax. That is, 1 777B would not be treated as a single value in free source form, and it would most likely result in a syntax error message.
A Boolean value represented by fewer than 86 octal digits is right justified; that is, it represents the rightmost bits of 256 bits.
When context is taken into account, the value is truncated on the left if it is too large for the context type. It is padded with 0 on the left if it is too small for the context type.
Note: For a literal constant, the letter B indicates octal digits; in an I/O format specification, the B descriptor indicates binary digits.
Examples:
| Boolean constant | Internal representation (octal) for a 64-bit word | |
| 0B | 0000000000000000000000 | |
| 77740B | 0000000000000000077740 |
Statement example:
I = 1357B |
The hexadecimal form consists of 1 to 64 hexadecimal digits consisting of 0 through 9, A through F, or a through f in either of the following two forms:
It can be specified as the letter X or x followed by a string of hexadecimal digits enclosed in apostrophes or quotations marks, as in X"FFF".
It can be specified with the X or x trailing the quoted string of digits, as in "FFF"X.
When a Boolean value contains 64 hexadecimal digits, the binary equivalents correspond to the content of each bit position in 4 64-bit words or eight 32-bit words.
A Boolean value represented by fewer than 64 hexadecimal digits is right justified; that is, it represents the rightmost bits of 256 bits.
An optional unary minus sign (-) is allowed within the quoted string.
When context is taken into account, the value is truncated on the left if it is too large for the context type. It is padded with 0 on the left if it is too small for the context type.
Examples:
| Boolean constant | Internal representation (octal) for a 64-bit word | |
| X'ABE' | 0000000000000000005276 | |
| X"-340" | 1777777777777777776300 | |
| X'1 2 3' | 0000000000000000000443 | |
| X'FFFFFFFFFFFFFFFF' | 1777777777777777777777 |
Statement examples:
J = X"28FF" K = X'-5A' |
A Hollerith constant is type Boolean. When a character constant is used in a bitwise logical expression, the expression is evaluated as if the value were Hollerith. A Hollerith constant can have a maximum of 32 characters.
When context is taken into account, the truncation or padding depends on the type of Hollerith syntax used.
For Hollerith using the letter H, the value is truncated on the right if it is too large for the context type. It is padded with blanks on the right if it is too small for the context type.
For Hollerith using the letter L, the value is truncated on the right if it is too large for the context type. It is padded with 0 on the right if it is too small for the context type.
For Hollerith using the letter R, the value is truncated on the left if it is too large for the context type. It is padded with 0 on the left if it is too small for the context type.
A Cray pointer is a variable whose value is the address of another entity, which is called a pointee. The Cray pointer type statement declares both the pointer and its pointee.
Note: The Fortran standard does not describe Cray pointer values.
Cray pointers are declared as follows:
POINTER (pointer, pointee) |
Fortran pointers are declared as follows:
POINTER :: [ object_name ] |
The two kinds of pointers cannot be mixed.
You can use pointers to access user-managed storage by dynamically associating variables and arrays to particular locations in a block of storage. Cray pointers do not provide convenient manipulation of linked lists because, for optimization purposes, it is assumed that no two pointers have the same value. Cray pointers also allow the accessing of absolute memory locations.
The range of a Cray pointer or Cray character pointer depends on the size of memory for the machine in use.
Restrictions on Cray pointers are as follows:
A Cray pointer variable should only be used to alias memory locations by using the LOC intrinsic.
A Cray pointer cannot be pointed to by another Cray or Fortran pointer; that is, a Cray pointer cannot also be a pointee or a target.
A Cray pointer cannot appear in a PARAMETER statement or in a type declaration statement that includes the PARAMETER attribute.
A Cray pointer variable cannot be declared to be of any other data type.
A Cray character pointer cannot appear in a DATA statement. For more information on Cray character pointers, see Section 4.3.8.
An array of Cray pointers is not allowed.
A Cray pointer cannot be a component of a structure.
Restrictions on Cray pointees are as follows:
A Cray pointee cannot appear in a SAVE, STATIC, DATA, EQUIVALENCE, COMMON, AUTOMATIC, or PARAMETER statement.
A Cray pointee cannot be a dummy argument; that is, it cannot appear in a FUNCTION, SUBROUTINE, or ENTRY statement.
A function value cannot be a Cray pointee.
A Cray pointee cannot be a structure component.
Note: Cray pointees can be of type character, but their Cray pointers are different from other Cray pointers; the two kinds cannot be mixed in the same expression.
The Cray pointer is a variable of type Cray pointer and can appear in a COMMON list or be a dummy argument in a subprogram.
The Cray pointee does not have an address until the value of the Cray pointer is defined; the pointee is stored starting at the location specified by the pointer. Any change in the value of a Cray pointer causes subsequent references to the corresponding pointee to refer to the new location.
Cray pointers can be assigned values in the following ways:
A Cray pointer can be set as an absolute address. For example:
Q = 0 |
Cray pointers can have integer expressions added to or subtracted from them and can be assigned to or from integer variables. For example:
P = Q + 100 |
However, Cray pointers are not integers. For example, assigning a Cray pointer to a real variable is not allowed.
The (nonstandard) LOC(3i) intrinsic function generates the address of a variable and can be used to define a Cray pointer, as follows:
P = LOC(X) |
The following example uses Cray pointers in the ways just described:
SUBROUTINE SUB(N)
COMMON POOL(100000), WORDS(1000)
INTEGER BLK(128), WORD64
REAL A(1000), B(N), C(100000-N-1000)
POINTER(PBLK,BLK), (IA,A), (IB,B), &
(IC,C), (ADDRESS,WORD64)
ADDRESS = LOC(WORDS) + 64
PBLK = LOC(WORDS)
IA = LOC(POOL)
IB = IA + 1000
IC = IB + N |
BLK is an array that is another name for the first 128 words of array WORDS. A is an array of length 1000; it is another name for the first 1000 elements of POOL. B follows A and is of length N. C follows B. A, B, and C are associated with POOL. WORD64 is the same as BLK(65) because BLK(1) is at the initial address of WORDS.
If a pointee is of a noncharacter data type that is one machine word or longer, the address stored in a pointer is a word address. If the pointee is of type character or of a data type that is less than one word, the address is a byte address. The following example also uses Cray pointers:
PROGRAM TEST REAL X(*), Y(*), Z(*), A(10) POINTER (P_X,X) POINTER (P_Y,Y) POINTER (P_Z,Z) INTEGER*8 I,J !USE LOC INTRINSIC TO SET POINTER MEMORY LOCATIONS !*** RECOMMENDED USAGE, AS PORTABLE CRAY POINTERS *** P_X = LOC(A(1)) P_Y = LOC(A(2)) !USE POINTER ARITHMETIC TO DEMONSTRATE COMPILER AND COMPILER !FLAG DIFFERENCES !*** USAGE NOT RECOMMENDED, HIGHLY NON-PORTABLE *** P_Z = P_X + 1 I = P_Y J = P_Z IF ( I .EQ. J ) THEN PRINT *, 'NOT A BYTE-ADDRESSABLE MACHINE' ELSE PRINT *, 'BYTE-ADDRESSABLE MACHINE' ENDIF END |
On a Cray X1 system, this prints the following:
Byte addressable machine |
Note: We do not recommend the use of pointer arithmetic because it is not portable.
For purposes of optimization, the compiler assumes that the storage of a pointee is never overlaid on the storage of another variable; that is, it assumes that a pointee is not associated with another variable or array. This kind of association occurs when a Cray pointer has two pointees, or when two Cray pointers are given the same value. Although these practices are sometimes used deliberately (such as for equivalencing arrays), results can differ depending on whether optimization is turned on or off. You are responsible for preventing such association. For example:
POINTER(P,B), (P,C) REAL X, B, C P = LOC(X) B = 1.0 C = 2.0 PRINT *, B |
Because B and C have the same pointer, the assignment of 2.0 to C gives the same value to B; therefore, B will print as 2.0 even though it was assigned 1.0.
As with a variable in common storage, a pointee, pointer, or argument to a LOC(3i) intrinsic function is stored in memory before a call to an external procedure and is read out of memory at its next reference. The variable is also stored before a RETURN or END statement of a subprogram.
If a pointee is declared as character type, its Cray pointer is a Cray character pointer.
Restrictions for Cray pointers also apply to Cray character pointers. In addition, the following restrictions apply:
When included in an I/O statement iolist, a Cray character pointer is treated as an integer.
If the length of the pointee is explicitly declared (that is, not of an assumed length), any reference to that pointee uses the explicitly declared length.
If a pointee is declared with an assumed length (that is, as CHARACTER *(*)), the length of the pointee comes from the associated Cray character pointer.
A Cray character pointer can be used in a relational operation only with another Cray character pointer. Such an operation applies only to the character address and bit offset; the length field is not used.
For more information on the Cray character pointer see Section 5.1.9.
| [1] | The use of 8-bit and 16-bit data causes severe performance penalties on the Cray X1 system. Therefore, the use of the -eh option is discouraged. |
| [2] | The use of 8-bit and 16-bit data incurs severe performance penalties on the Cray X1 system. Therefore the use of the -eh option is discouraged. |
| Prev Section | Table of Contents | Title Page | Index | Next Section |
| What Is Meant by type in Fortran | Up one level | Derived Types |