| United States-English |
|
|
|
![]() |
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 3 Data types and data objectsRepresentation of literal constants |
|
The formats of constants for each of the intrinsic data types are described below. A signed integer literal constant is:
Following are examples of integer constants:
In DATA statements, additional forms of unsigned constants are permitted for initializing integer variables. The values are expressed in binary, octal, or hexadecimal notation, and are collectively known as BOZ constants. The formats are:
where digit-string contains only the digits 0 and 1.
where digit-string contains only the digits 0, ..., 7. A hexadecimal constant is one of:
where hex-digit-string contains only the characters 0, ..., 9, A, ..., F,a,...,f. Following are examples of BOZ constants:
initializes i, j, and k to the decimal value 74. As an extension, HP Fortran 90 also allows octal constants with a trailing O, and hexadecimal constants with a trailing X. For example:
are alternative representations to those used in the example above. HP Fortran 90 also extends the range of use of these constants to contexts other than initializing integers. These extensions are described in “Typeless constants”. A signed real literal constant is one of:
sign and digit-string are explained in “Integer constants”. The use of Q is an HP Fortran 90 extension. If no kind parameter is present, or if the exponent letter E is present, then the default kind representation will be used. If the exponent letter is D,the kind parameter used will be 8, and if the exponent letter is Q,the kind parameter will be 16. If both an exponent and a kind parameter are specified, the exponent letter must be E. Following are examples of real constants: Table 3-2 Title not available (Real constants)
A complex literal constant has the form:
The kind parameter of the complex value will correspond to the kind parameter of the part with the larger storage requirement. Following are examples of complex constants: Table 3-3 Title not available (Complex constants)
A character literal constant is one of:
The delimiting characters are not part of the constant. If it is required to place a single quote in a string delimited by single quotes then two single quotes must be used; and similarly for double quotes. Following are examples of character constants:
For compatibility with C usage, HP Fortran 90 allows the backslash character (\) to be used as an escape character in character strings. A compile-time option, the +escape option (see Chapter 13), must be used to enable this feature. It denotes that the character following in the string has a significance that is not normally associated with the character. The effect is to ignore the backslash character, and either substitute an alternative value for the character following, or to interpret the character as a quoted value. The escape characters that are recognized and their effects are described in Table 3-4 “ Escape characters”. Table 3-4 Escape characters
Thus:
is a valid string where +escape is used. The backslash is not counted in the length of the string. If \& appears at the end of a line when the +escape option is active, the & will not be treated as a continuation indicator. A logical literal constant is one of:
Following are examples of logical constants:
HP Fortran 90 extends the uses of binary, octal, and hexadecimal constants beyond those prescribed in the Fortran 90 Standard. Binary, octal, and hexadecimal constants ( BOZ constants) can be used wherever an intrinsic literal constant of any numeric or logical type is permitted. HP Fortran 90 also allows Hollerith constants to be used in these contexts and where a character type is required. The format of BOZ constants is described in “BOZ constants”. If possible, the type attached to a typeless constant is derived from the magnitude of the constant and the context in which it appears. When used as one operand of a binary operator, it assumes the type of the other operand. If it is used as the right-hand side of an assignment, the type of the object on the left-hand side is assumed. When used to define the value within a structure constructor, it assumes the type of the corresponding component. If appearing in an array constructor, it assumes the type of the first element of the constructor. The following rules and restrictions also apply to BOZ constants:
Title not available (Examples)
Hollerith constants have the format:
Following are examples of Hollerith constants:
where bb represents two space characters, to make the length equal to 5. Hollerith constants may appear anywhere that a BOZ constant can appear, and additionally where a character string is valid. When there is a mismatch in lengths the constant will be truncated on the right, or padded on the right with space characters. If a Hollerith constant is used as an argument to the conversion functions INT and LOGICAL, KIND=1 and KIND=2 are added as possible values for KIND=a (see the BOZ rules earlier in this section); these apply when the length of the constant is 1 or 2 characters/bytes. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||