BOZ literal constants, a puzzle for us Standard-loving types.
- From: Toon Moene <toon@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Mar 2007 20:08:30 +0200
Lectoribus Salutem,
A colleague of mine came up with the following, very simple, and very annoying (if it hits you) error message when using gfortran:
Program:
$ cat bozlitconst.f
program test
integer i
data i / z'FFFF8000' /
print *, i
end
$ /usr/rel/bin/gfortran -c bozlitconst.f
bozlitconst.f:3.26:
data i / z'FFFF8000' /
1
Error: Arithmetic overflow converting INTEGER(16) to INTEGER(4) at (1)
Relevant quote from the Fortran 2003 Standard:
If a [DATA STATEMENT 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 [INTEGER
literal constant] with a [KIND] that specifies the represen-
tation method with the largest decimal exponent range
supported by the processor.
The error arises from the fact that
1. BOZ literal constants are INTEGERs and, hence, signed numbers.
2. The largest representable INTEGER in gfortran (on AMD64 GNU/Linux
systems) is a 16 byte integer (irrelevant in this case - it would
be just as wrong were it an 8 byte integer).
Therefore:
The BOZ literal constant above is a positive number, and
a positive number of that magnitude can not be represented
by a 32 bit signed integer.
Question to my fellow J3 Committee members: Did we really mean to outlaw this (it has an obvious meaning: stuff the 32 bits that FFFF8000 hex represents into a 32 bit integer and "damn the torpedo's".
g77 accepts it without even warning about it, so this probably means most compilers accept it (g77 was rather late to the game and, consequently, a follower of fashion).
I open for suggestions.
--
Toon Moene - e-mail: toon@xxxxxxxxxxxxxxxxxxxx - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.indiv.nluug.nl/~toon/
Who's working on GNU Fortran: http://gcc.gnu.org/ml/gcc/2007-01/msg00059.html
.
- Follow-Ups:
- Re: BOZ literal constants, a puzzle for us Standard-loving types.
- From: Brooks Moses
- Re: BOZ literal constants, a puzzle for us Standard-loving types.
- From: glen herrmannsfeldt
- Re: BOZ literal constants, a puzzle for us Standard-loving types.
- From: Steven G. Kargl
- Re: BOZ literal constants, a puzzle for us Standard-loving types.
- Prev by Date: Re: variable names for different fortrans
- Next by Date: Re: calculation accuracy
- Previous by thread: unable to view symbols in gdb
- Next by thread: Re: BOZ literal constants, a puzzle for us Standard-loving types.
- Index(es):
Relevant Pages
|