j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Clarification needed for required behavior in output edge case #217

Open klausler opened 3 years ago

klausler commented 3 years ago
character(11) :: buffer(3)
character(10) :: quotes = '""""""""""'
write(buffer,*,delim="QUOTE") quotes
print 1, buffer
1 format('>',a10,'<')
end

A Fortran implementation is required to emit two adjacent ("on the external medium") instances of the delimiter character whenever there is one in effect and it appears in a character value in list-directed and NAMELIST output. The two instances of the delimiter are not allowed to have a record boundary between them, perhaps because delimited character output should be suitable for later use as list-directed input, which forbids a record separator between the repeated delimiters.

It is impossible to satisfy this requirement when the first instance of the delimiter character falls at the end of a fixed-length record, including the important case of internal output to a character array. It is not clear what the best behavior should be when this actually happens, and existing Fortran implementations differ in their executions of the sample program above. Two crash due to fixed output record overflow, one fails to duplicate the delimiter in any case, and two cross the record boundary (one with odd extra spaces inserted later).

I suspect that the onus may be on the program(mer) to avoid getting into this situation at the execution of a conforming program, but no existing implementation responds with a useful run-time error that might explain the infraction.