Question about allocatable functions in gfortran

Nick Fort nickfort.newsgroups@gmail.com
Wed Jul 28 08:00:00 GMT 2010


On 28 July 2010 08:13, Tobias Burnus <burnus@net-b.de> wrote:
> Nick Fort wrote:
>> I've been playing with some F2003 features, which are reportedly
>> implemented in gfortran 4.6 (and probably earlier): allocatable dummy
>> arguments, and allocatable functions.
>>
>
> Allocatable function results and dummy arguments indeed work - however,
> you use a related feature, which is not yet supported:
>
> real, dimension(:), allocatable :: vector_call
> vector_call = random_vector()
>
>
> Here, vector_call is unallocated and is supposed to get allocated upon
> assignment. That's allowed in Fortran 2003 but not yet implemented in
> gfortran. Cf. "Assignment to an allocatable array" at the F2003 status at

Ah, I see! All right, that clears that up. Well, almost. How come the
subroutine version works? I mean, I know it's through arguments, but
it can still assign to an allocatable array in the calling program
(see the first code I pasted, being careful to add the pluses that
"Hey! Paste It" removed). I'm sure it's some subtlety I'm missing, but
I thought I'd ask anyway.

> - http://fortranwiki.org/fortran/show/Fortran+2003+status
> -
> http://www.fortranplus.co.uk/resources/fortran_2003_2008_compiler_support.pdf
> - http://gcc.gnu.org/wiki/Fortran2003Status
>
> (if you use other compilers: note, that some require some special option
> to enable (re)allocate on assignment.)
>
> and the description of the items at
> - ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1648.pdf
>
> The gfortran bug is:
> - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35810
>
> Like with all software development, especially with volunteer-based
> ones, it is difficult to give an estimate when it will be implemented;
> to my knowledge no one currently works on this features - but as one of
> the few missing F2003 features, its priority raises as other F2003
> features get implemented.

I understand.  If I knew anything about writing compilers, I'd jump
right in, but I guess I have to leave it to more knowledgeable people
than myself. I do, however, look forward to the gfortran release that
supports the complete F2003 set one day.

> Steve Kargl wrote:
>> On Tue, Jul 27, 2010 at 06:58:25PM -0700, Jerry DeLisle wrote:
>>
>>>  length_call:            0
>>> At line 23 of file alloc.f90
>>> Fortran runtime error: Attempt to DEALLOCATE unallocated 'vector_call'
>>>
>>>
>> Which is somewhat correct.
>>
>> function random_vector() result(vector)
>>    implicit none
>>    real, dimension(:), allocatable :: vector
>>    integer :: length
>>    real :: length_real
>>
>>    if (allocated(vector)) deallocate(vector)
>>
>> The above statement is invalid
>>
>
> Actually, the code looks valid to me: "vector" should be unallocated;
> while attempting to deallocate it is invalid, "allocated(vector)" should
> always return .false.

That's pretty much what I thought. I know it's somewhat redundant, but
I sometimes like to include additional safety measures, just in case I
need to use some compiler somewhere one day that does something
unexpected.

> Tobias
>



More information about the Fortran mailing list