[J3] Allocatation upon assignment of a dummy argument in an interoperable procedure
Bill Long
longb at cray.com
Mon Oct 7 17:02:34 EDT 2019
The statement
foo = 42
and the statements
allocate( foo ); foo = 42
should do the same thing, since the INTENT(OUT) will (should) ensure that the argument is deallocated on entry. So, while it is possible that the descriptor is messed up somehow, that would not be a sufficient explanation of why one works and the other does not. If the descriptor is bad, both versions should fail in the Fortran allocate routine.
It would be useful to see the C code that sets up the descriptor.
Also, as an aside, it is usually considered poor programming style to use the same name for a dummy argument and the binding label for the routine.
Cheers,
Bill
> On Oct 7, 2019, at 3:53 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> How does it fail?
>
> Was the C descriptor initialized by CFI_establish and then passed changed to the interoperable subroutine, or was the C descriptor changed after it was established?
>
> Bob Corbett
>
>> On Oct 7, 2019, at 11:09 AM, Vipul Parekh via J3 <j3 at mailman.j3-fortran.org> wrote:
>>
>> Is the following code conforming?
>>
>> subroutine sub(foo) bind(C, name="foo")
>> !.. Argument list
>> integer(c_int), allocatable, intent(out) :: foo
>> foo = 42 !<-- fails
>> !allocate( foo ); foo = 42 !<-- works
>> end subroutine
>>
>> When foo is invoked from a companion C processor with a successfully
>> established C descriptor with the right attributes, the use of
>> ALLOCATE statement followed by the assignment works as I expect.
>> However allocation upon assignment, as shown above, fails.
>>
>> Thank you,
>> Vipul Parekh
>
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray, a Hewlett Packard Enterprise company/ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list