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

Vipul Parekh parekhvs at gmail.com
Tue Nov 29 22:08:29 UTC 2022


On Tue, Nov 29, 2022 at 4:46 PM Vipul Parekh <parekhvs at gmail.com> wrote:

> ..
>    abstract interface
>       function Ifoo(arg) result(foo)
>          character(4) :: foo, arg
>       end function
>    end interface
>

Thanks Brad for trying that out, ICEs really hurt when trying things out
with compilers!

This probably makes no difference to the ICE but I did mean the abstract
interface to be
    abstract interface
      function Ifoo(arg) result(foo)
         character(*) :: arg
         character(4) :: foo
      end function
   end interface

Re: "since the interface of proc no longer matches it is not legal", both
Intel Fortran and gfortran don't complain about the following and give
'abcd' as the output.  It will be interesting what NAG says about this case
where the middleman `sub` is taken out!

   character(len=4), external :: foo
   abstract interface
      function Ifoo(arg) result(foo)
         character(len=*) :: arg
         character(len=4) :: foo
      end function
   end interface
   procedure(Ifoo), pointer :: proc
   proc => foo
   print *, proc("ab")
end

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

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


More information about the J3 mailing list