Besides decimal constants, Fortran also supports binary (
o) and hexadecimal (
z) integer constants. The
syntax is: `prefix quote digits quote', were the prefix is
z, quote is either
" and the digits are for binary
7, and for hexadecimal between
Up to Fortran 95, BOZ literals were only allowed to initialize
integer variables in DATA statements. Since Fortran 2003 BOZ literals
are also allowed as argument of
CMPLX; the result is the same as if the integer BOZ
literal had been converted by
TRANSFER to, respectively,
As GNU Fortran extension the intrinsic procedures
DCMPLX are treated alike.
As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
be specified using the
X prefix, in addition to the standard
Z prefix. The BOZ literal can also be specified by adding a
suffix to the string, for example,
Furthermore, GNU Fortran allows using BOZ literal constants outside
DATA statements and the four intrinsic functions allowed by Fortran 2003.
In DATA statements, in direct assignments, where the right-hand side
only contains a BOZ literal constant, and for old-style initializers of
integer i /o'0173'/, the constant is transferred
TRANSFER had been used; for
COMPLEX numbers, only
the real part is initialized unless
CMPLX is used. In all other
cases, the BOZ literal constant is converted to an
INTEGER value with
the largest decimal representation. This value is then converted
numerically to the type and kind of the variable in question.
real :: r = b'0000001' + 1 initializes
2.0.) As different compilers implement the extension
differently, one should be careful when doing bitwise initialization
of non-integer variables.
Note that initializing an
INTEGER variable with a statement such
DATA i/Z'FFFFFFFF'/ will give an integer overflow error rather
than the desired result of -1 when
i is a 32-bit integer
on a system that supports 64-bit integers. The `-fno-range-check'
option can be used as a workaround for legacy code that initializes
integers in this manner.