[J3] Question on iomsg in DTIO

Brad Richardson everythingfunctional at protonmail.com
Mon Mar 18 14:32:18 UTC 2024


Hi Reinhold,

I definitely think this is something that needs to be addressed. I've been working on related things with respect to supporting this kind of feature, and have some thoughts about how this question should be answered. I think your paper adequately demonstrates the issue.

IMO this should be a special case where generic resolution should be allowed to distinguish between an argument that is allocatable and one that is not. Your example as written is (and still would be) invalid, as it calls `wf` with an unallocated iomsg argument. In the case that the actual argument was allocated, the `wf` subroutine would be called and things would work as expected. This is backwards compatible with how things worked prior to 2023. However, if you also included a `wf2` with an identical interface and implementation except that the iomsg argument was allocatable, deferred length, it would be called if the actual argument was also allocatable, deferred length. As examples,

The following is valid currently, and would remain so,

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

ALLOCATE(character(len=46) :: msg)
WRITE(*,*, iostat=ierr, iomsg=msg) o
IF (ierr /= 0) THEN
WRITE(*,*) ierr, len(msg), msg ! 129 46 Sorry, wf only pretends to be a DTIO procedure
END IF
END PROGRAM

The following would now be valid, and work as expected/shown

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

INTERFACE WRITE(FORMATTED)
MODULE PROCEDURE wf
MODULE PROCEDURE wf2
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
SUBROUTINE wf2(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=:), allocatable, INTENT(inout) :: iomsg

iostat = 130
iomsg = 'Sorry, wf2 only pretends to be a DTIO procedure'

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

WRITE(*,*, iostat=ierr, iomsg=msg1) o
IF (ierr /= 0) THEN
WRITE(*,*) ierr, len(msg1), msg1 ! 129 46 Sorry, wf only pretends to be a DTIO procedure
END IF
WRITE(*,*, iostat=ierr, iomsg=msg2) o
IF (ierr /= 0) THEN
WRITE(*,*) ierr, len(msg2), msg2 ! 130 47 Sorry, wf2 only pretends to be a DTIO procedure
END IF
END PROGRAM

Making this change to the standard will be a bit of a challenge though.

Regards,
Brad

On Mon, 2024-03-18 at 11:02 +0000, Bader, Reinhold via J3 wrote:

> 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/fa1983de/attachment.htm>


More information about the J3 mailing list