Illegal internal write?



The f95 standard 9.4.4.4, and the f2003 standard 9.5.3.4, both say:

"If an internal file has been specified, an input/output list item
shall not be in the file or associated with the file."

In the WRITE statement in the following program, the input/output
list item is IMHO not in the file, but it is an expression whose
value depends on that of the file. Does that make it "associated"
as that term is used in those Fortran standards?

PROGRAM testnoforall
CHARACTER :: fmts(3)*24 = (/"I0 ","ES11.4","F8.4 "/)
WRITE(fmts,'(A)')("(1X,A,"//trim(fmts(i))//")", i=1,3)
PRINT "(A)",fmts
END PROGRAM testnoforall

Five f95 compilers that I tried accepted the program at compile time.
At run time, four of them printed
(1X,A,I0)
(1X,A,ES11.4)
(1X,A,F8.4)
as I had hoped. However, one (gfortran) printed
(1X,A,) (1X,A,) (1X,A,)

The quoted rule is not in a Constraint, so I can't complain if
a program defying it compiles and runs, but if the program is
standard-conforming, which output is correct?

--
John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 5341 fax (+64)(4)463 5045
.



Relevant Pages

  • Re: Comparision of C Sharp and C performance
    ...     double dif; ... compile time with runtime operations. ... you assume that all C compilers will do the constant division ... you don't evaluate an invariant in a for loop IF the preprocessor ...
    (comp.lang.c)
  • Re: Error writing on unit 22
    ... Fortran standards. ... different compilers. ... It says "read/write attempted after endfile." ... another system dependent hack that worked on that system? ...
    (comp.lang.fortran)
  • Re: Strange error msg.
    ... All good compilers have an array subscript bounds check ... to a single precision argument, ... easy to do with constants--pass 1.0 to a subroutine that ... the compiler to make a slew of compile time error checks. ...
    (comp.lang.fortran)
  • Breakem good and hard...
    ... will fail in as many different C compilers as possible, ... time or compile time. ...
    (comp.lang.c)
  • Re: merge of character strings
    ... * What happens in mergeif lengths of strings ... are not known at compile time, but are in fact equal at run time? ... Dick's version compiled and ran with all 4 compilers. ...
    (comp.lang.fortran)