Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

hexadecimal numbers

Roman1
New Contributor I
812 Views

I am trying to understand how to use hexadecimal numbers properly.  When I compile the following program, I am getting the following warning when assigning a hex value to a variable:

warning #6473: Fortran 2008 does not allow boz constant in this context.   [Z'0000000F']

However, there is no warning if I fist set a PARAMETER to this value, and then assign it to a variable.  Is this the correct behavior?

 

program test_hexint
implicit none
integer a, b
integer,parameter:: c = Z'0000000f'

a = Z'0000000f'  ! warning #6473: Fortran 2008 does not allow boz constant in this context.

b = c  ! no warning

write(*,*) a, b
stop
end program test_hexint

 

0 Kudos
3 Replies
FortranFan
Honored Contributor II
812 Views

You will find the Fortran standard (e.g., section 4.7 of Fortran 2008) state, "A binary, octal, or hexadecimal constant (boz-literal-constant) is a sequence of digits that represents an ordered sequence of bits. Such a constant has no type" (the bolded emphasis is mine) and later provide a constraint "C4102 (R463) A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, or where
explicitly allowed in subclause 13.7 as an actual argument of an intrinsic procedure."

So you can try the following to make it standard compliant:

program test_hexint

   implicit none

   integer a, b
   integer, parameter:: c = int( Z'0000000f', kind=kind(c))

   a = int( Z'0000000f', kind=kind(a))

   b = c  ! no warning

   write(*,*) a, b

   stop

end program test_hexint

 

0 Kudos
Roman1
New Contributor I
812 Views

Thanks for the information.  I thought that hex numbers can be used like any other integer.  I am still confused about the parameter statement:

integer,parameter:: c = Z'0000000f'

Is the above line standard compliant?  My guess is that it is not, since it is not a DATA statement.  However, the compiler is not displaying any warning messages.

 

0 Kudos
Steven_L_Intel1
Employee
812 Views

It is indeed nonstandard to use a BOZ constant directly in a PARAMETER - that we don't give a standards warning for this is a known problem that will be fixed in a future release.

0 Kudos
Reply