[J3] Question on iomsg in DTIO

Bader, Reinhold Reinhold.Bader at lrz.de
Mon Mar 18 11:02:40 UTC 2024


Dear all, 

 

attached a draft paper for which I'd like some feedback (especially from
/interp) before I submit it to the J3 

site.

 

Cheers

Reinhold

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240318/5e2d8a84/attachment.htm>
-------------- next part --------------
To: J3                                                     J3/##-###
From: Reinhold Bader
Subject: interp request for iomsg in DTIO procedure
Date: 2024-Mar-20
References: 20-122, 24-007r1

Introduction
~~~~~~~~~~~~

With Fortran 2023, restrictions on iomsg variables were removed, so a 
deferred-length string passed into a I/O statement by the user would 
be allocated to the needed length.
This paper poses the question what happens if the I/O statement
has been overloaded by a DTIO procedure.

Example
~~~~~~~

Consider the following program:

MODULE mod
   TYPE :: t
      INTEGER :: i
   END TYPE

   INTERFACE WRITE(FORMATTED)
      MODULE PROCEDURE wf
   END INTERFACE
CONTAINS
   SUBROUTINE wf(dtv, unit, iotype, v_list, iostat, iomsg)
      CLASS(t), INTENT(in) :: dtv
      INTEGER, INTENT(in) :: unit, v_list(:)
      CHARACTER(len=*), INTENT(in) :: iotype
      INTEGER, INTENT(out) :: iostat
      CHARACTER(len=*), INTENT(inout) :: iomsg

      iostat = 129
      iomsg = 'Sorry, wf only pretends to be a DTIO procedure'

   END SUBROUTINE
END MODULE
PROGRAM p
   USE mod
   TYPE(t) :: o = t(4)
   INTEGER :: ierr
   CHARACTER(len=:), ALLOCATABLE :: msg

   WRITE(*,*, iostat=ierr, iomsg=msg) o ! (Y)
   IF (ierr /= 0) THEN
       WRITE(*,*) ierr, len(msg), msg ! (X)
   END IF
END PROGRAM

Questions
~~~~~~~~~

(1) does the program conform to the standard?
(2) if it conforms, what is the value of len(iomsg) inside the 
    procedure wf?
(3) if it conforms, what will the statement marked (X) print?

Discussion
~~~~~~~~~~

On the face of it, it would seem that the answer to (1) 
must be "yes", since the clearly stated intention of
20-122 is that the appearance of an allocatable msg in 
statement (Y) should imply its allocation as needed. 
On the other hand, there seems to be no way how the 
implementor of a DTIO procedure can account for this 
situation, since the dummy argument iomsg simply does not 
have the ALLOCATABLE attribute.
Given the above example, one could argue that the 
standard simply does not establish an interpretation, so the 
program is invalid. However, this would appear to be a 
disservice to programmers.

Possible resolutions
~~~~~~~~~~~~~~~~~~~~

- exceptionally, permit a specific DTIO implementation
  that has an allocatable iomsg. Might be difficult since
  the DTIO might also be explicitly called e.g. recursively. 

- add a restriction that allocatable strings for iomsg 
  cannot be used in case DTIO overloads are active in the 
  parent I/O statement.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6777 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240318/5e2d8a84/attachment.p7s>


More information about the J3 mailing list