[J3] Can a procedure pointer have character(*) result type?
Brad Richardson
everythingfunctional at protonmail.com
Tue Nov 29 20:02:05 UTC 2022
At first I expected that a function could not have character(*) result type, so you can't have a pointer to a function that can't be defined, but even nagfor only reported that
function foo(arg)
character(*) :: foo, arg
foo = arg // "cd"
end function
is obsolecent. I.e.
$ nagfor -c assumed_length_character_result.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7115
Obsolescent: assumed_length_character_result.f90, line 4: Assumed-length CHARACTER function
[NAG Fortran Compiler normal termination, 1 warning]
However, trying to run your example I got,
$ nagfor example.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7115
Obsolescent: example.f90, line 12: Assumed-length CHARACTER function
Obsolescent: example.f90, line 18: Assumed-length CHARACTER function
Error: example.f90: Explicit interface required for SUB from $main$ - argument PROC (no. 1) is a POINTER
[NAG Fortran Compiler error termination, 1 error, 2 warnings]
I played around with it a bit more and got as far as
character(2) :: cc
character(*), external :: foo
character(*), pointer :: foo2
cc = "ab"
foo2 => foo
call sub(foo2, cc)
contains
subroutine sub(proc, arg)
character(*) :: arg
!character(*) :: proc !! This is OK
character(*), external, pointer :: proc !! Question: is this conforming?
print*, proc(arg)
end
end
function foo(arg)
character(*) :: foo, arg
foo = arg // "cd"
end function
but still got errors like
$ nagfor example.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7115
Error: example.f90, line 14: External function FOO cannot be declared as CHARACTER(*) outside of its subprogram
Error: example.f90, line 14: Invalid class of assumed length CHARACTER item FOO2
[NAG Fortran Compiler pass 1 error termination, 2 errors]
So as far as I can tell, the line you point to as questionable may in fact be valid, but I can't figure out how you could make use of it in a standard conforming way (assuming the nagfor compiler is a reasonable stand-in for checking standards conformance).
Brad
On Tue, 2022-11-29 at 19:10 +0000, Daniel C Chen via J3 wrote:
> Consider the following example:
>
> character(2) :: cc
>
> character(4), external :: foo
>
> cc = "ab"
>
> call sub(foo, cc)
>
> end
>
> subroutine sub(proc, arg)
>
> character(*) :: arg
>
> !character(*) :: proc !! This is OK
> character(*), external, pointer :: proc !! Question: is this conforming?
>
> print*, proc(arg)
>
> end
>
> function foo(arg)
>
> character(*) :: foo, arg
>
> foo = arg // "cd"
>
> end function
> Is it legal to declare a dummy procedure pointer to have character(*) result type? I couldn’t find anything wording in the standard that disallow it, but want to confirm if this is a legal program.
>
> Thanks,
> Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221129/25940a80/attachment-0001.htm>
More information about the J3
mailing list