https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107031
--- Comment #6 from kargl at gcc dot gnu.org --- (In reply to anlauf from comment #3) > (In reply to kargl from comment #2) > > gfortran's current behavior is correct. > > > > > > 12.3.4.4 File position after data transfer > > > > In all other cases, the file is positioned after the record just > > read or written and that record becomes the preceding record. > > > > 12.8.3 ENDFILE statement > > > > Execution of an ENDFILE statement for a file connected for sequential > > access writes an endfile record as the next record of the file. > > > > After reading '5', the file is position at the record that contains '6'. > > So, ENDIFLE writes the endfile record after the record with '6'. > > Hmm, interpretation of text? > Yes, it is interpretation. Let <R> denote the start of record and </R> the end of the record. One has <R>5</R><R>6</R><R>7</R> After reading '5', the file is positioned to after that record. If * denotes the current file, then one can have <R>5</R>*<R>6</R> or <R>5</R><R>*6</R> Both meet the requirement of 12.3.4.4. Now by 12.8.3, the endfile will give <R>5</R>EOF while the latter would give <R>5</R><R>*6</R>EOF.