(j3.2006) TS 29113: INTENT(out) and TYPE(*)
Bill Long
longb
Wed Mar 7 08:47:23 EST 2012
On 3/7/12 3:18 AM, Tobias Burnus wrote:
> Dear all,
>
> after re-thinking the issue, I think using TYPE(*) with INTENT(OUT) is
> possible. However, one needs to pass to Fortran procedures [those without
> BIND(C)] not only the address of the data but the same meta information
> as with CLASS(*). That information is needed to do deallocation and default
> initialization.
Deallocation is not a problem since ALLOCATABLE is not allowed for
assumed-type (C407a). Default initialization is a problem, though.
>
> That's possible, but then NOTE 5.1 is highly misleading as it states:
> "An assumed-type object that is not assumed-shape and not assumed-rank is
> intended to be passed as the C address of the object."
>
> I think that should state that this only applies to BIND(C) procedures.
> (Or INTENT(OUT) should be disallowed for TYPE(*).)
>
Adding INTENT(OUT) to the list of disallowed attributes for assumed type
in C407a would solve the problem, though a bit of overkill. More
narrowly, we could prohibit INTENT(OUT) with TYPE(*) if the actual type
has (sub)components with default-initialization. That would have to be
a non-constraint requirement.
>
> As the full type information has to be available, the restriction in
> 6.3 does not seem to be required:
>
> "An assumed-type dummy argument shall not correspond to an actual argument
> that is of a derived type that has type parameters, type-bound procedures,
> or final procedures."
>
> (I wonder whether it would apply to allocatable components; I think even
> with that restriction, one needs to finalize them.)
>
> * * *
>
> For BIND(C) with TYPE(*) the situation for INTENT(OUT) is simpler as many
> types are not interoperable. (I think in particular allocatable components
> are still not allowed, unless I missed some fine print.)
>
> However, I think the following part should not only apply to allocatable
> dummies but also to nonallocatable dummies with default initialization.
> (That default initialization is allowed, is implied by C516.)
>
> "When a C function is invoked from a Fortran procedure via an interface"
> with an INTENT(OUT) allocatable dummy argument, and the actual argument
> in the reference to the C function is an allocated allocatable variable,
> the variable is deallocated on invocation (before execution of the C
> function begins)."
>
> Namely, I expect some wording that the default initialization of the
> intent(out) dummy is also done in the involking Fortran procedure.
What about the case of C calling a Fortran procedure with BIND(C)? The
Fortran callee would not have enough information to initialize the
components.
Cheers,
Bill
>
> Tobias
>
>
> On Mon, Mar 05, 2012 at 10:28:25AM +0100, Tobias Burnus wrote:
>> type t
>> integer :: a = 5
>> end type t
>> type(t) :: var
>> var%a = 8
>> call one(x)
>> print *, var%a
>> contains
>> subroutine one(x)
>> type(*) :: x
>> call two(x)
>> end subroutine two
>> subroutine two(y) ! optionally with Bind(C).
>> type(*), intent(out) :: y
>> end subroutine
>> end
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3
mailing list