[RFC] BOZ literals
Tobias Burnus
burnus@net-b.de
Thu Dec 6 14:18:00 GMT 2007
Hi all,
some ideas for BOZ literal constants.
* * *
Fortran 95 only allows BOZ literals in DATA statements - and only for
INTEGER variables.
Fortran 2003 has the same restriction, but allows the BOZ as "a"
argument of REAL, DBLE and INT, and as "x" and "y" argument of CMPLX.
gfortran (-std=gnu) allows BOZ everywhere and regards them as integer BOZ.
With some compilers, the meaning of the BOZ changes depending of the LHS
type.
g77: By default everywhere integer, but with -ftypeless-boz the value
depended on the LHS.
* * *
Ok, the attached patch does the following:
- Give an error with -std=f* that BOZ for non-integer variables is not
allowed in DATA
- Otherwise, convert the BOZ in the data statement to the according type
- Handle for REAL(), DBLE(), and CMPLX() BOZ in the Fortran 2003 way.
I am thinking of handling:
variable = BOZ
as
variable = variable_type(BOZ) ! e.g. var_real = real(BOZ)
as long as the RHS is only the BOZ literal and not an expression.
(and with an appropriate error message for -std=f*).
TODO:
* REAL(z'333') does not work as gfc_simplify_real is never called. I
could not yet figure out the code path.
* -std=f2003 does not give an error if the BOZ is used outside a DATA
statement and outside REAL/DBLE/CMPLX/INT.
* Fix some parts of the patch
* Add test cases
* Update documentation.
Comments? Is this the right way to go?
Tobias
PS: The patch was motivated by a recent comp.lang.fortran discussion,
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/2ad94287d7f8a6f0/
and a recent bug report
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34345
See also my diagnostic PR 34342 and the older PRs 18026 and 29471.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: boz.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20071206/4d8fd506/attachment.ksh>
More information about the Fortran
mailing list