[J3] Can a procedure pointer have character(*) result type?
Brad Richardson
everythingfunctional at protonmail.com
Tue Nov 29 21:51:12 UTC 2022
Hi Vipul,
Unfortunately I get an ICE with that as well. I'm guessing that since the interface of proc no longer matches it is not legal, but I'm not entirely certain.
Regards,
Brad
On Tue, 2022-11-29 at 16:46 -0500, Vipul Parekh wrote:
> 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/8b948ed4/attachment-0001.htm>
More information about the J3
mailing list