[J3] Can a procedure pointer have character(*) result type?
Brad Richardson
everythingfunctional at protonmail.com
Tue Nov 29 20:39:39 UTC 2022
Vipul,
Your example without pointer worked fine with NAG, but I get an internal compiler error (ICE) when you add it back in. I believe one of the error messages from one of my earlier attempts at having sub simply be a contained subprogram applies here though, namely:
character(2) :: cc
character(4), external :: foo
cc = "ab"
call sub(foo, cc)
contains
! File sub.f90
subroutine sub(proc, arg)
character(*) :: arg
character(*), external, pointer :: proc
print*, proc(arg)
end
end
! File foo.f90
function foo(arg)
character(*) :: foo, arg
foo = arg // "cd"
end function
$ nagfor example.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7115
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.
Brad
On Tue, 2022-11-29 at 15:26 -0500, Vipul Parekh via J3 wrote:
> Oops sorry, Brad, I meant including the POINTER attribute and what NAG says then. Thanks,
>
> ! File p.f90
> character(2) :: cc
> character(4), external :: foo
> interface
> subroutine sub(proc, arg)
> character(*) :: arg
> character(*), intent(in) external, pointer :: proc
> end
> end interface
> cc = "ab"
> call sub(foo, cc)
> end
>
> ! File sub.f90
> subroutine sub(proc, arg)
> character(*) :: arg
> character(*), intent(in), external, pointer :: proc
> print*, proc(arg)
> end
>
> ! File foo.f90
> function foo(arg)
> character(*) :: foo, arg
> foo = arg // "cd"
> end function
>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221129/08777418/attachment-0001.htm>
More information about the J3
mailing list