(j3.2006) Would there be a technical problem if...
Bill Long
longb
Wed Jan 17 15:47:59 EST 2018
> On Jan 17, 2018, at 1:56 PM, Van Snyder <Van.Snyder at jpl.nasa.gov> wrote:
>
>
> Anyway, I still don't know whether there's a technical problem for the
> standard or for implementations to allow the passed-object argument to
> be an array.
I agree that none of the posts really addressed this. I?m not the expert on this stuff, but will try at least some comments.
The passed-object dummy argument gets associated with the object that is the data-ref in the syntax
call data-ref%binding-name
If the passed-object dummy is an array, then the data-ref would either need to be an array or broadcast to each element of the dummy. Or the TBP needs to be elemental. Interestingly in section on procedure reference, the data-ref in the call statement is allowed to be an array. What that means in the case of the dummy being a scalar and the procedure not elemental is unclear. I tried a naive example:
module modu
type van
integer :: i = 1
procedure(van_tbp),pointer :: van_tbp
contains
procedure :: tbp => van_tbp
end type van
contains
subroutine van_tbp(pass_obj)
class (van) :: pass_obj
print *, "executed tbp", pass_obj%i
end subroutine van_tbp
end module modu
program test
use modu
type(van) :: obj_ref, array_ref(10)
print *, "call to obj_ref"
call obj_ref%tbp
print *, "call to array_ref"
call array_ref(:)%tbp
end program test
With 4 compilers tried, 3 gave errors for mismatched ranks of the actual and dummy arguments. The 4th accepted the code and printed output as if the dummy were a rank-1 array of size 10. (The ?1? repeated 10 times.) This is not too impossible considering that the dummy is declared CLASS and hence would be passed as a pointer to a descriptor. The descriptor contains enough information about rank, bounds, etc. to allow the code to run. Malcolm or Tom can comment on the conformance of the code, but relying on this working is clearly not portable in practice.
If the compiler allowed you to declared the passed-object argument as an array (constraint violation now), then the data-ref in the call could not be a scalar. That sort of limitation might seem unacceptable to some.
Cheers,
Bill
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list