[J3] [EXTERNAL] Can a type-bound procedure be passed as an actual argument

Bader, Reinhold Reinhold.Bader at lrz.de
Wed Jan 11 19:59:09 UTC 2023


Enabling this would be dicey, though, because for polymorphic objects you get dynamic dispatch, so
the compiler cannot check against the dummy signature at compile time.

Cheers
Reinhold

Von: J3 <j3-bounces at mailman.j3-fortran.org> Im Auftrag von Clune, Thomas L. (GSFC-6101) via J3
Gesendet: Mittwoch, 11. Januar 2023 19:59
An: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Clune, Thomas L. (GSFC-6101) <thomas.l.clune at nasa.gov>
Betreff: Re: [J3] [EXTERNAL] Can a type-bound procedure be passed as an actual argument

This is not permitted.  (But would be nice!)


R1524 actual-arg is expr

24 or variable

25 or procedure-name

26 or proc-component-ref

27 or conditional-arg

28 or alt-return-spec

29

t1%foo is a binding name which is not in that list.

Real_foo can of course be passed, but it is not directly accessible through t1.


  *   Tom

From: J3 <j3-bounces at mailman.j3-fortran.org<mailto:j3-bounces at mailman.j3-fortran.org>> on behalf of j3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>>
Reply-To: j3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>>
Date: Wednesday, January 11, 2023 at 1:08 PM
To: j3 <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] [J3] Can a type-bound procedure be passed as an actual argument

Hi All,
Consider the following code
Case 1:
  type dt
   contains
    procedure, nopass :: foo => real_foo
  end type
  interface
    subroutine real_foo()
    end
  end interface
  type(dt) :: t1
  call sub1(t1%foo)    !!! Is it legal to pass t1%foo as actual argument?
end
Case 2:
module m
  type dt
   contains
    procedure :: foo => real_foo
  end type
contains
    subroutine real_foo(this)
      class(dt) :: this
    end
end

program main
use m
  type(dt) :: t1
  call sub1(t1%foo)   !!! Is it legal to pass t1%foo as actual argument?

end

I couldn’t find any wording in the standard (F2018) that prohibits the two usages above, and yet a couple of compilers that I have access to flags error message.

Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20230111/d911a820/attachment-0001.htm>


More information about the J3 mailing list