daver@hcx1.UUCP (01/05/87)
Suppose the following statement is used to read from an empty file: read (11, '(i5)', end=10) i The end= branch should be taken, because an "end-file" record is encountered. Now suppose no input variable is given: read (11, '(i5)', end=10) Should the end= branch be taken or not (using the same empty file) ? I know of 2 compilers which do not take the branch. Another one does. The standard describes what happens during a data transfer, but in the second example, no data is being transferred. I see no explicit mention of when an end-of-file should be detected except for the vague phrase "when a read is executed".
steved@sun.uucp (Steve Dever) (01/07/87)
In article <44400008@hcx1> daver@hcx1.UUCP writes: > >Suppose the following statement is used to read from an empty file: > . . . > read (11, '(i5)', end=10) > >Should the end= branch be taken or not (using the same empty file) ? >I know of 2 compilers which do not take the branch. Another one does. > At least 1 record is always read or written by a formatted I/O statement so the end= branch should be taken since the end-file record was read. This is specified in section 12.9.5.2 of the FORTRAN standard: During formatted data transfer, data are transferred with editing between the entities specified by the input/output list and the file. The current record and possibley additional records are read or written. -- --------------------------- Steve Dever steved@Sun.COM or Sun Microsystems sun!steved
firth@sei.cmu.edu (Robert Firth) (01/07/87)
In article <44400008@hcx1> daver@hcx1.UUCP writes: > >Suppose the following statement is used to read from an empty file: > > read (11, '(i5)', end=10) i > >The end= branch should be taken, because an "end-file" record is >encountered. > >Now suppose no input variable is given: > > read (11, '(i5)', end=10) > >Should the end= branch be taken or not (using the same empty file) ? >I know of 2 compilers which do not take the branch. Another one does. > >The standard describes what happens during a data transfer, but in the >second example, no data is being transferred. I see no explicit mention >of when an end-of-file should be detected except for the vague phrase >"when a read is executed". I believe the END= should not be executed. ANSI X3.9-1978 explains how an IO data transfer occurs in 12.9. In particular, these two steps are executed in this order (4) Position the file prior to data transfer (5) Transfer data between the file and the entities specified by the input-output list (if any) The above means an empty IO list is legal. Section 12.2.3 (File Position) is explicit that you can validly position at the beginning of an empty file. Section 12.6 (1) says an end-of-file condition exists if an endfile record is encountered during the READING of a file. Put all three together, and the correct behaviour seems to be that the READ statement is executed, no data are transferred, the file remains positioned at the beginning, and control passes on sequentially. The compiler that takes the branch would appear to be non-compliant.
firth@sei.cmu.edu (Robert Firth) (01/07/87)
In article <11040@sun.uucp> steved@sun.UUCP (Steve Dever) writes: >In article <44400008@hcx1> daver@hcx1.UUCP writes: >> >>Suppose the following statement is used to read from an empty file: >> > . . . >> read (11, '(i5)', end=10) >> >>Should the end= branch be taken or not (using the same empty file) ? >>I know of 2 compilers which do not take the branch. Another one does. >> > >At least 1 record is always read or written by a formatted I/O statement >so the end= branch should be taken since the end-file record was read. >This is specified in section 12.9.5.2 of the FORTRAN standard: > > During formatted data transfer, data are transferred with editing between > the entities specified by the input/output list and the file. The > current record and possibley additional records are read or written. > > >-- >--------------------------- >Steve Dever steved@Sun.COM > or >Sun Microsystems sun!steved Sigh! i sent my response before reading Steve's, and now I'm confused. He's surely right for unformatted IO, since 12.9.5.1 says "exactly one record is read or written". The sentence he quotes for formatted IO indeed implies that at least one record is read. But that appears to contradict what I found in 12.9. Please permit a rapid withdrawal of my last post - I just don't know!
geiser@apollo.uucp (Wayne Geiser) (01/08/87)
I agree with Steve Dever. In section 13.3 (page 13-3 lines 47 through 51) the Standard says: ... Note that an empty format specification of the form ( ) may be used only if no list items are specified; in this case, one input record is skipped or one output record containing no characters is written. ... I realize that the example given (READ(11,'(I5)',END=10)) does, indeed contain a format specification. The control for the read comes from the io list as described in the same section (13.3 page 13-4 lines 16 through 22): Whenever format control encounters a repeatable edit descriptor in a format specification, it determines whether there is a corresponding item specified by the input/output list. If there is such an item, it transmits appropriately edited information between the item and the record, and then format control proceeds. If there is no corresponding item, format control terminates. Obviously, in this case 'format control terminates' with the first edit descriptor. The input record (in this case an endfile record) is still 'skipped' and the end-of-file condition exists as per the definition in section 12.6 (page 12-8 lines 47 through 53): An end-of-file condition exists if either of the following events occurs: (1) An endfile record is encountered during the reading of a file connected for sequential access. In this case, the file is positioned after the endfile record. Wayne Geiser Apollo Computer, Inc. {wanginst, yale, uw-beaver, brunix, utah-cs}!apollo!geiser