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

Vipul Parekh parekhvs at gmail.com
Tue Nov 29 21:46:15 UTC 2022


On Tue, Nov 29, 2022 at 3:40 PM Brad Richardson via J3 <
j3 at mailman.j3-fortran.org> wrote:

> Vipul,
>
> Your example without pointer worked fine with NAG, but I get an internal
> compiler error (ICE) when you add it back in. ..
> Error: example.f90, line 4: Argument PROC (number 1) of SUB is a procedure
> pointer but actual argument FOO is just a procedure
> Obsolescent: example.f90, line 12: Assumed-length CHARACTER function
> Obsolescent: example.f90, line 19: Assumed-length CHARACTER function
> [NAG Fortran Compiler error termination, 1 error, 2 warnings]
>
> So I'm still of the opinion that the declaration in question is valid, but
> that it can't be used in a standard conforming way. ..
>

Thanks Brad.

It appears the NAG compiler might be looking for the following main program?

 ! File p.f90
   character(2) :: cc
   character(4), external :: foo
   interface
      subroutine sub(proc, arg)
         character(*) :: arg
         character(*), external, pointer :: proc
      end
   end interface
   abstract interface
      function Ifoo(arg) result(foo)
         character(4) :: foo, arg
      end function
   end interface
   procedure(Ifoo), pointer :: proc
   proc => foo
   cc = "ab"
   call sub(proc, cc)
end

! File sub.f90
subroutine sub(proc, arg)
   character(*) :: arg
   character(*), external, pointer :: proc
   print *, proc(arg)
end

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

This variant with the character(len=4) trick in the interface similar to
character(len=4) declaration in the EXTERNAL statement works with Intel
Fortran and it gives 'abcd' as the program output.  Not sure if the program
conforms though it seems ok to me.

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


More information about the J3 mailing list