[Numpy-discussion] f2py with allocatable arrays

Ondřej Čertík ondrej.certik@gmail....
Thu Jul 5 18:00:17 CDT 2012


On Tue, Jul 3, 2012 at 5:27 PM, Sturla Molden <sturla@molden.no> wrote:
> Den 04.07.2012 01:59, skrev Sturla Molden:
>> But neither was the case here. The allocatable was a dummy variable in
>> a subroutine's interface, declared with intent(out). That is an error
>> the compiler should trap, because it is doomed to segfault.
>
> Ok, so the answer here seems to be:
>
> In Fortran 90 is compiler dependent.
> In Fortran 95 it is an error.
> In extensions to Fortran 95 it is legal.
> In Fortran 2003 and 2008 it is legal.

That's exactly right. I only use allocatable arrays (in intent(out) as
well), never pointers,
and I never call deallocate(), because Fortran frees it for me automatically
(even for intent(out)). I think it's a good programming practice, as there
can't be any memory leaks.

If Fortran 95 compatibility is required, I changed allocatable,
intent(out) variables
to pointers, and then go up the call chain and explicitly deallocate
the arrays when
they are not needed, to avoid memory leaks.

Ondrej


More information about the NumPy-Discussion mailing list