[J3] Concerned out paper 20-122r1: Edits for US14 (auto-allocate characters)
Vipul Parekh
parekhvs at gmail.com
Sun Mar 8 01:13:43 UTC 2020
Dan, Steve:
As noted by Peter Klausler at the GitHub site for Fortran issues (
https://github.com/j3-fortran/fortran_proposals/issues/160#issuecomment-593650274),
paper 20-122r1 titled "Edits for US14 (auto-allocate characters)" which has
a Status of "Passed" and which is dated Friday 28th Feb 2020 in the meeting
documents for 221 is of concern from 2 aspects pertaining to an already
allocated scalar deferred length character variable in a WRITE statement to
an internal file.
Consider the following code for which I expect a conforming processor to
produce an output of 'len(s) = 20':
character(len=:), allocatable :: s
allocate( character(len=20) :: s )
write (s, fmt="(g0)") "Hello World!"
print *, "len(s) = ", len(s)
end
Note 19-252r2 gave the edit for 12.4 Internal Files [216:12-14]p2 as
"A record of the internal file becomes defined by writing the record.
When the record is an allocatable character scalar declared
with deferred length and is allocated sufficiently long, or is not
an allocatable character scalar declared with deferred length,
if the number of characters written in a record
is less than the length of the record, the remaining portion
of the record is filled with blanks. The number of characters
to be written shall not exceed the length of the record.
Otherwise, the character variable is allocated with the
length needed to contain the record."
and based on this, I expect no change to the output mentioned above.
However 20-122r1 lists the Edit for [216:12-14]p2 as
"A record of the internal file becomes defined by writing the record.
- If the internal file is an allocatable, deferred-length character
scalar variable, it becomes defined as if by intrinsic assignment of
the record.
- Otherwise, if the number of characters written in a record is less
than the length of the record, the remaining portion of the record is
filled with blanks; the number of characters to be written shall not
exceed the length of the record."
which would change the output of the program shown above to 'len(s) = 12'.
So what got passed at 20-122r1 is of concern in terms of:
a) Consistency with paper 19-252r2 which was passed at 220 and to which
20-122r1 refers, and
b) Backward compatibility with the current standard.
On the other hand, should the Edit in question in 20-122r1 be modified by
introducing one more word 'unallocated' it would immediately alleviate
both the concerns:
"A record of the internal file becomes defined by writing the record.
- If the internal file is an unallocated allocatable, deferred-length
character scalar variable, it becomes defined as if by intrinsic assignment
of the record.
- Otherwise, if the number of characters written in a record is less than
the length of the record, the remaining portion of the record is filled
with blanks; the number of characters to be written shall not exceed the
length of the record."
Please note the above concerns actually are present with all the situations
involving an allocated scalar deferred length character variable that are
being addressed in US14. With the following example code,
character(len=:), allocatable :: msg
integer :: lun, istat
allocate( character(len=256) :: msg )
open( newunit=lun, file="https://j3-fortran.org/", iostat=istat,
iomsg=msg )
print *, "len(msg) = ", len(msg)
end
I expect a conforming processor to output 'len(s) = 256' whereas with
20-122r1, the output is indeterminate.
Can you please look into this and follow up with J3?
Thank you,
Vipul Parekh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200307/f810ba8e/attachment.htm>
More information about the J3
mailing list