- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page