[Bug fortran/39587] New: Reading integer from "" gives end-of-file instead of reading a 0

burnus at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Mar 30 12:59:00 GMT 2009


The following program works with NAG f95, g95, sunf95, ifort but fails with a
  Fortran runtime error: End of file
in gfortran. I think the program is valid.

---------------------------------
implicit none
character(len=5) :: str
integer :: a
str = ''
a = 5
read(str,'(5x,i1)') a
print *, a
if(a /= 0) call abort()
end
---------------------------------

If one uses a logical value rather than an integer, ifort/openf95/sunf95 print
.false. and g95/NAG f95/gfortran print an error.

I think "" -> .false. is a vendor extension. If I read the standard correctly,
this extension makes the compiler invalid (i.e. the compiler needs to diagnose
this rather than doing something else); however, I might be wrong and this
extension is acceptable.

I asked at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/68cb46bf0e610043

 * * *

See "10.6.1 Numeric editing": "On Input [...] A field containing only blanks is
considered to be zero."

(Such a statement is missing from "10.6.2 Logical editing".)

I did not quickly find the place which allows "" (rather than " ") to be 0 and
not end-of-file. I also did not find the place which requires the end-of-file
error rather allowing for .false.


-- 
           Summary: Reading integer from "" gives end-of-file instead of
                    reading a 0
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39587



More information about the Gcc-bugs mailing list