This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: SEG-FAULT problem with gfortran ?
Of course, passing in an "allocatable" array with "intent(out)" and
allocating it the subroutine works fine. That is, when the code
returns from the allocating subroutine call, the array is still
allocated - i.e., it's still there with whatever values the subroutine
populated it with.
---John
On Tue, Nov 20, 2012 at 3:54 AM, N.M. Maclaren <nmm1@cam.ac.uk> wrote:
> On Nov 20 2012, John Chludzinski wrote:
>>
>>
>> I'm translating some very ugly C++ code to Fortran (using gfortran on
>> Fedora 17). In the process, I've sometimes become too literal in my
>> translation. So I translated an ugly piece of C++ into the following
>> call:
>>
>> ...
>>
>>
>> Whereas the first code is ugly, it still should have worked. Correct?
>
>
> No.
>
>
>> Maybe the allocatable qualifiers in the first code were the problem?
>
>
> Yes. ALLOCATABLE, INTENT(OUT) arguments are deallocated on entry to
> the procedure. What you seem to want to do is to use the existing
> space to write to, and the correct solution is INTENT(OUT) without the
> ALLOCATABLE.
>
> The only thing that gfortran MIGHT do better is to have a warning in
> -Wextra for ALLOCATABLE, INTENT(OUT), saying "Are you sure that you
> know what the standard specifies?" It's dubiously a good idea, but
> I am throwing it out for possible consideration.
>
>
> Regards,
> Nick Maclaren.
>