(j3.2006) Fwd: BOZ incompatiability in Fortran standards
Steidel, Jon L
jon.l.steidel
Fri Oct 6 17:15:18 EDT 2017
You can't put 36 bits into a 32 bit container. Whether that happens silently or verbosely, it was still happens.
From: J3 [mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of Dan Nagle
Sent: Friday, October 6, 2017 4:48 PM
To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
Subject: (j3.2006) Fwd: BOZ incompatiability in Fortran standards
Hi,
With Steve's permission, this may be of interest.
Begin forwarded message:
From: "Steven G. Kargl" <kargl at troutmask.apl.washington.edu<mailto:kargl at troutmask.apl.washington.edu>>
Subject: BOZ incompatiability in Fortran standards
Date: October 4, 2017 at 13:26:12 MDT
To: danlnagle at me.com<mailto:danlnagle at me.com>
Reply-To: kargl at uw.edu<mailto:kargl at uw.edu>
Hi Dan,
I know/suspect that you are busy with finalizing F2015. I just
noticed a major incompatibility for BOZ in a data-statement between
F95 and F03 and the later standards F08 and F15. Neither F08
nor F15 acknowledge this problem. Here are the excerpts:
F95, p. 63
If a data-statement-constant is a boz-literal-constant, the corresponding
object shall be of type integer. A data-stmt-constant that is a
boz-literal-constant is treated as if the constant were an int-literal-
constant with a kind-param that specifies the representation method with
the largest decimal exponent range supported by the processor.
F2003, p. 89
If a data-stmt-constant is a boz-literal-constant, the corresponding
variable shall be of type integer. The boz-literal-constant is treated
as if it were an int-literal-constant with a kind-param that specifies
the representation method with the largest decimal exponent range
supported by the processor.
F2008, p. 106
If a data-stmt-constant is a boz-literal-constant, the corresponding
variable shall be of type integer. The boz-literal-constant is treated
as if it were converted by the intrinsic function INT (13.7.81) to type
integer with the kind type parameter of the variable.
F2015, p. 117
If a data-stmt-constant is a boz-literal-constant, the corresponding
variable shall be of type integer. The boz-literal-constant is treated
as if it were converted by the intrinsic function INT (16.9.100) to type
integer with the kind type parameter of the variable.
For this discussion, assume the kind type parameters for two integer
types are enumerated with 4 and 8. Further, assume that INTEGER(8)
has a larger decimal exponent range than INTEGER(4). Then, the above
statements, changes how a Fortran processor interprets
INTEGER(4) I ! Yes, the 4 is nonstandard, but used for discussion.
DATA I/Z'FFFFFFFFF'/ ! F95/F03 treat BOZ as INTEGER(8),
PRINT *, I
END
In F95 and F03, Z'FF' is converted/treated as an INTEGER(8). In F08
and F15, Z'FF' is converted directly to INTEGER(4).
For gfortran the current behavior gives
troutmask:sgk[248] gfortran6 -static -o z b.f90 -Wall && ./z
b.f90:2:23:
data i /z'fffffffff'/
1
Error: Arithmetic overflow converting INTEGER(16) to INTEGER(4) at (1).
This check can be disabled with the option '-fno-range-check'
--
Steve
http://troutmask.apl.washington.edu/~kargl/
--
Cheers!
Dan Nagle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171006/e8505778/attachment-0001.html>
More information about the J3
mailing list