Typeless literal constants
A typeless constant does not have an intrinsic type in XL Fortran.
Hexadecimal, octal, binary, and Hollerith constants can be used in any situation
where intrinsic literal constants are used, except as the length specification
in a type declaration statement (although typeless constants can be used in
a type_param_value in CHARACTER type
declaration statements). The number of digits recognized in a hexadecimal,
octal, or binary constant depends on the context in which the constant is
used.
Hexadecimal constants
The form of a hexadecimal constant is:

>>-+-+-X-+--+-'--hexadecimal_number--'-+-+---------------------><
| '-Z-' '-"--hexadecimal_number--"-' |
+-+-'--hexadecimal_number--'-+--+-X-+-+
| '-"--hexadecimal_number--"-' '-Z-' |
'-Z--hexadecimal_number---------------'
- hexadecimal_number
- is a string composed of digits (0-9) and letters
(A-F, a-f). Corresponding uppercase
and lowercase letters are equivalent.
The Znn...nn form of a hexadecimal constant
can only be used as a data initialization value delimited by slashes. If this
form of a hexadecimal constant is the same string as the name of a constant
you defined previously with the PARAMETER attribute, XL Fortran recognizes
the string as the named constant.
If 2x hexadecimal digits are present, x bytes are represented.
See Using typeless constants for information on how XL Fortran interprets
the constant.
Examples of hexadecimal constants
Z'0123456789ABCDEF'
Z"FEDCBA9876543210"
Z'0123456789aBcDeF'
Z0123456789aBcDeF ! This form can only be used as an initialization value
Octal constants
The form of an octal constant is:

>>-+-O--+-'--octal_number--'-+-+-------------------------------><
| '-"--octal_number--"-' |
'-+-'--octal_number--'-+--O-'
'-"--octal_number--"-'
- octal_number
- is a string composed of digits (0-7)
Because an octal digit represents 3 bits, and a data object represents
a multiple of 8 bits, the octal constant may contain more bits than are needed
by the data object. For example, an INTEGER(2) data object can be
represented by a 6-digit octal constant if the leftmost digit is 0 or 1; an INTEGER(4) data object can be represented by an 11-digit
constant if the leftmost digit is 0, 1, 2,
or 3; an INTEGER(8) can be represented by a 22-digit constant
if the leftmost digit is 0 or 1.
See Using typeless constants for information on how the constant
is interpreted by XL Fortran.
Examples of octal constants
O'01234567'
"01234567"O
Binary constants
The form of a binary constant is:

>>-+-B--+-'--binary_number--'-+-+------------------------------><
| '-"--binary_number--"-' |
'-+-'--binary_number--'-+--B-'
'-"--binary_number--"-'
- binary_number
- is a string formed from the digits 0 and 1
If 8x binary digits are present, x bytes are represented.
See Using typeless constants for information on how XL Fortran interprets
the constant.
Examples of binary constants
B"10101010"
'10101010'B
Hollerith constants
The form of a Hollerith constant is:

>>-n--H--character_string--------------------------------------><
A Hollerith constant consists of a nonempty string of characters
capable of representation in the processor and preceded by nH,
where n is a positive unsigned integer constant representing the
number of characters after the H. n cannot specify a
kind type parameter. The number of characters in the string may be from 1
to 255.
Note:
If you specify nH and fewer than n characters are specified after the n, any blanks that are
used to extend the input line to the right margin are considered to be part
of the Hollerith constant. A Hollerith constant can be continued on a continuation
line. At least n characters must be available for the Hollerith
constant.
XL Fortran also recognizes escape sequences in Hollerith constants, unless
the -qnoescape compiler option is specified. If a Hollerith constant
contains an escape sequence, n is the number of characters in the
internal representation of the string, not the number of characters in the
source string. (For example, 2H\"\" represents a Hollerith constant
for two double quotation marks.)
XL Fortran provides support for multibyte characters within character constants,
Hollerith constants, H edit descriptors, character-string edit descriptors,
and comments. This support is provided through the -qmbcs option.
Assignment of a constant containing multibyte characters to a variable that
is not large enough to hold the entire string may result in truncation within
a multibyte character.
Support is also provided for Unicode characters and filenames. If the environment
variable LANG is set to UNIVERSAL and the -qmbcs compiler
option is specified, the compiler can read and write Unicode characters and
filenames.
See Using typeless constants for information on how the constant
is interpreted by XL Fortran.
Using typeless constants
The data type and length of a typeless constant are
determined by the context in which you use the typeless constant. XL Fortran does
not convert the data type and length until you use them and context is understood.
- If you compile your program with the -qctyplss compiler option,
character initialization expressions follow the rules that apply to Hollerith
constants.
- A typeless constant can assume only one of the intrinsic data types.
- When you use a typeless constant with an arithmetic or logical unary operator,
the constant assumes a default integer type.
- When you use a typeless constant with an arithmetic, logical, or relational
binary operator, the constant assumes the same data type as the other operand.
If both operands are typeless constants, they assume a type of default integer
unless both operands of a relational operator are Hollerith constants. In
this case, they both assume a character data type.
- When you use a typeless constant in a concatenation operation, the constant
assumes a character data type.
- When you use a typeless constant as the expression on the right-hand side
of an assignment statement, the constant assumes the type of the variable
on the left-hand side.
- When you use a typeless constant in a context that requires a specific
data type, the constant assumes that data type.
- When you use a typeless constant as an initial value in a DATA statement, STATIC statement, or type declaration statement, or as the constant value
of a named constant in a PARAMETER statement, or when the typeless
constant is to be treated as any noncharacter type of data, the following
rules apply:
- If a hexadecimal, octal, or binary constant is smaller than the length
expected, XL Fortran adds zeros on the left. If it is longer, the compiler truncates
on the left.
- If a Hollerith constant is smaller than the length expected, the compiler
adds blanks on the right. If it is longer, the compiler truncates on the right.
- If a typeless constant specifies the value of a named constant with a
character data type having inherited length, the named constant has a length
equal to the number of bytes specified by the typeless constant.
- When a typeless constant is treated as an object of type character (except
when used as an initial value in a DATA, STATIC, type declaration,
or component definition statement), the length is determined
by the number of bytes represented by the typeless constant.
- When you use a typeless constant as part of a complex constant, the constant
assumes the data type of the other part of the complex constant. If both parts
are typeless constants, the constants assume the real data type with length
sufficient to represent both typeless constants.
- When you use a typeless constant as an actual argument, the type of the
corresponding dummy argument must be an intrinsic data type. The dummy argument
must not be a procedure, pointer, array, object of derived type, or alternate
return specifier.
- When you use a typeless constant as an actual argument, and:
- The procedure reference is to a generic intrinsic procedure,
- All of the arguments are typeless constants, and
- There is a specific intrinsic procedure that has
the same name as the generic procedure name,
the reference to the generic name will be resolved through the specific
procedure.
- When you use a typeless constant as an actual argument, and:
- The procedure reference is to a generic intrinsic procedure,
- All of the arguments are typeless constants, and
- There is no specific intrinsic procedure that has the same name
as the generic procedure name,
the typeless constant is converted to default integer. If a specific
intrinsic function takes integer arguments, the reference is resolved through
that specific function. If there are no specific intrinsic functions, the
reference is resolved through the generic function.
- When you use a typeless constant as an actual argument, and:
- The procedure reference is to a generic intrinsic procedure, and
- There is another argument specified that is not a typeless constant,
the typeless constant assumes the type of that argument. However, if you specify the compiler option -qport=typlssarg, the
actual argument is converted to default integer. The selected specific intrinsic
procedure is based on that type.
- When you use a typeless constant as an actual argument, and the procedure
name is established to be generic but is not an intrinsic procedure, the generic
procedure reference must resolve to only one specific procedure. The constant
assumes the data type of the corresponding dummy argument of that specific
procedure. For example:
INTERFACE SUB
SUBROUTINE SUB1( A )
REAL A
END SUBROUTINE
SUBROUTINE SUB2( A, B )
REAL A, B
END SUBROUTINE
SUBROUTINE SUB3( I )
INTEGER I
END SUBROUTINE
END INTERFACE
CALL SUB('C0600000'X, '40066666'X) ! Resolves to SUB2
CALL SUB('00000000'X) ! Invalid - ambiguous, may
! resolve to either SUB1 or SUB3
- When you use a typeless constant as an actual argument, and the procedure
name is established to be only specific, the constant assumes the data type
of the corresponding dummy argument.
- When you use a typeless constant as an actual argument, and:
- The procedure name has not been established to be either generic or specific,
and
- The constant has been passed by reference,
the constant assumes the default integer size but no data type, unless
it is a Hollerith constant. The default for passing a Hollerith constant is
the same as if it were a character actual argument. However, using the compiler
option -qctyplss=arg will cause a Hollerith constant to be passed
as if it were an integer actual argument. See Resolution of procedure references for
more information about establishing a procedure name to be generic or specific.
- When you use a typeless constant as an actual argument, and:
- The procedure name has not been established to be either generic or specific,
and
- The constant has been passed by value,
the constant is passed as if it were a default integer for hexadecimal,
binary, and octal constants.
If the constant is a Hollerith constant and
it is smaller than the size of a default integer, XL Fortran adds blanks on the
right. If the constant is a Hollerith constant and it is larger than 8 bytes, XL Fortran truncates
the rightmost Hollerith characters. See Resolution of procedure references for
more information about establishing a procedure name to be generic or specific.
- When you use a typeless constant as a selector in the ASSOCIATE statement, the constant assumes default integer type.
- When you use a typeless constant in any other context, the constant assumes
the default integer type, with the exception of Hollerith constants. Hollerith
constants assume a character data type when used in the following situations:
- An H edit descriptor
- A relational operation with both operands being Hollerith constants
- An input/output list
- If a typeless constant is to be treated as a default integer but the value
cannot be represented within the value range for a default integer, the constant
is promoted to a representable kind.
- A kind type parameter must not be replaced with a logical constant even
if -qintlog is on, nor by a character constant even if -qctyplss is on, nor can it be a typeless constant.
Examples of typeless constants in expressions
INT=B'1' ! Binary constant is default integer
RL4=X'1' ! Hexadecimal constant is default real
INT=INT + O'1' ! Octal constant is default integer
RL4=INT + B'1' ! Binary constant is default integer
INT=RL4 + Z'1' ! Hexadecimal constant is default real
ARRAY(O'1')=1.0 ! Octal constant is default integer
LOGICAL(8) LOG8
LOG8=B'1' ! Binary constant is LOGICAL(8), LOG8 is .TRUE.