[J3] Can a procedure pointer have character(*) result type?

Daniel C Chen cdchen at ca.ibm.com
Tue Nov 29 20:34:21 UTC 2022


Correction
2. the assumed-length dummy procedure is always allowed but it must be on external functions. (I.e. internal, module procedures are not allowed).
Should be read
2. The assumed-length function result …must be on external functions….

From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Daniel C Chen via J3
Sent: November 29, 2022 3:28 PM
To: Vipul Parekh <parekhvs at gmail.com>; General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Daniel C Chen <cdchen at ca.ibm.com>
Subject: [EXTERNAL] Re: [J3] Can a procedure pointer have character(*) result type?

Hi Vipul and Brad, Thanks for the reply. 1. I understand the assumed-length function result is obsolescent. 2. the assumed-length dummy procedure is always allowed but it must be on external functions. (I. e. internal, module procedures are
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
Hi Vipul and Brad,
Thanks for the reply.

1. I understand the assumed-length function result is obsolescent.
2. the assumed-length dummy procedure is always allowed but it must be on external functions. (I.e. internal, module procedures are not allowed).

The question I have is regarding if a assumed-length dummy procedure pointer is allowed.

Vipul is right that I should have included an interface block in main for sub if I want to declare ‘proc’ as a dummy procedure pointer argument because it has the POINTER attribute.
However, the original question remains that if a declaration ‘character(*), external, pointer :: proc’ is legal to declare ‘proc’ to be a dummy procedure pointer.

I don’t see why it can’t. The call to sub(foo, cc) should work for both cases no matter if dummy argument ‘proc’ is a dummy procedure or dummy procedure pointer.

Thanks
Daniel

From: Vipul Parekh <parekhvs at gmail.com<mailto:parekhvs at gmail.com>>
Sent: November 29, 2022 3:18 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>>
Cc: Daniel C Chen <cdchen at ca.ibm.com<mailto:cdchen at ca.ibm.com>>
Subject: [EXTERNAL] Re: [J3] Can a procedure pointer have character(*) result type?

On Tue, Nov 29, 2022 at 3: 01 PM Vipul Parekh <parekhvs@ gmail. com> wrote: .. Based on a quick glance at the standard, I think it still supports "Assumed character length functions" though it has marked them as obsolescent.   See
ZjQcmQRYFpfptBannerStart
This Message Is From an Untrusted Sender
You have not previously corresponded with this sender.
ZjQcmQRYFpfptBannerEnd


On Tue, Nov 29, 2022 at 3:01 PM Vipul Parekh <parekhvs at gmail.com<mailto:parekhvs at gmail.com>> wrote:
..
Based on a quick glance at the standard, I think it still supports "Assumed character length functions" though it has marked them as obsolescent.  See B.3.6 in 22-007 (WG5 N191, Dec. 2021) document. ..

Hello Daniel,

Forgot to add a sentence: I too couldn't find in the standard that might prohibit "Assumed character length functions" as dummy procedures.

Hi Brad,

What happens if you try the following with the NAG compiler?  Note the explicit interface for `sub`:
! File p.f90
   character(2) :: cc
   character(4), external :: foo
   interface
      subroutine sub(proc, arg)
         character(*) :: arg
         !character(*) :: proc                      !! This is OK
         character(*), external :: proc    !! Question: is this conforming?
      end
   end interface
   cc = "ab"
   call sub(foo, cc)
end

! File sub.f90
subroutine sub(proc, arg)
   character(*) :: arg
   !character(*) :: proc                      !! This is OK
   character(*), external :: proc    !! Question: is this conforming?
   print*, proc(arg)
end

! File foo.f90
function foo(arg)
   character(*) :: foo, arg
   foo = arg // "cd"
end function

I expect the resulting program to output '`abcd'.

Regards,
Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221129/d1d4883f/attachment-0001.htm>


More information about the J3 mailing list