Why are parens required around format strings?

No, but I can see how you might think that. If you don’t supply a width, a default is provided based on the type. For a four-byte integer, (i) is equivalent to (i12). See Default Widths for Data Edit Descriptors (intel.com)

Above I mentioned an extension called “short field termination”, and on further reading I find I mischaracterized it. A short record doesn’t trigger this, only a comma following the value. Terminating Short Fields of Input Data (intel.com)

I’m not sure where you figured in non-advancing reads, which VAX FORTRAN certainly didn’t have. In no case would it leave the current position in the middle of a record.

So let’s fast-forward to DEC Fortran 90, which did have non-advancing reads. If the feature you seem to be suggesting was there, then consider the following program:

i = 999
j = 999
read (*,'(i)',advance='no') i
read (*,'(i)') j
print *, i, j
end

and an input of 3 4. You would expect the values 3 and 4 to be printed. What happens instead is that the first read fails because the default width of 12 is greater than the length of the record.

1 Like