GFortran BOZ-literals incompatible with F2003. Fix?

Brooks Moses brooks.moses@codesourcery.com
Fri Jan 12 19:45:00 GMT 2007


I just came across a spot where our GNU-specific extensions (as 
documented in version 4.2 and up) for BOZ-literal constants are 
incompatible with Fortran 2003, and I think we should reconsider this 
before the 4.2 release.

Consider this bit of example code:

     X = REAL(Z'00FF')

Fortran 95 limits BOZ literals to DATA statements, where they can only 
be associated with integers, and are interpreted as a representation of 
an integer constant having the largest kind supported on the system. 
Thus, under strict F95, that sample is illegal.

Currently, GNU Fortran allows BOZ literals in initialization expressions 
and assignments, where they are interpreted in the same fashion.  Thus, 
in the sample code, Z'FF is converted to 255_8, and then transformed to 
255.0.

Fortran 2003, however, also extends the allowable places for BOZ 
literals to include the arguments of DBLE, REAL, INT, or CMPLX.  The INT 
definition agrees with our usage, but in the case of REAL, DBLE, and 
CMPLX, the BOZ literal is interpreted as the bit pattern of the 
representation in memory.  Thus, the sample code will result in X being 
something quite different, like 3.57331108E-43.


As I mentioned, the first version of GFortran that documents this 
particular extension is 4.2, which we haven't released yet.  (I think it 
may also be the first version that implements it, but I'm not sure.)  If 
we do release it with this extension, we will then have a regression 
against documented behavior once we implement this bit of F2003.

The unfortunate thing is that this extension is one that's also a 
documented part of G77, so we'll get a regression against that in any 
case.  More unfortunately, a bit of searching at Google Code Search on 
"lang:fortran Z'[0-9A-Z]" indicates that usage of this particular 
extension isn't all that rare, either.  So it seems that it would be a 
bad idea just to revoke support for the extension entirely.

My thought is that we should probably make this a legacy extension 
rather than a GNU extension, or otherwise have some means of producing a 
warning whenever a bare BOZ-literal is used.  Thoughts?  Differing 
opinions?  Any ideas for how to implement both sanely without weird 
special-casing?

- Brooks



More information about the Fortran mailing list