Re: Fortran and .NET (C#)
- From: "apm" <Contributor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Sep 2005 14:30:27 -0400
"Richard Maine" <nospam@xxxxxxxxxxxxx> wrote in message
news:11jis403u85m5f2@xxxxxxxxxxxxxxxxxxxxx
> apm wrote:
>
>> I seem to remember Fortran 90 allowing arrays to be returned by
>> functions. Was there "garbage collection" in Fortran 90 or was there
>> reference counting?
>
> No. And no. Neither one. Compilers *may* do such things, but that is
> completely optional (and most compilers don't, though a few do).
>
> For functions returning arrays that are either explicit-sized or
> allocatable (the allocatable case isn't allowed until f2003 or f95+TR),
> the language is designed such that you don't need either of those. The
> language makes it well-defined exactly when any such allocated storage
> gets released. No reference counts or garbage collection is needed.
>
> For functions returning pointers.... well.... I strongly recommend against
> doing that (and have so in several previous posts here).
Is it true that memory that a Fortran pointer "points" to may not be
reclaimed when the pointer goes out of scope? This would be like C/C++ or
worse.
>
> Recall that, unlike C, Fortran doesn't force you into using pointers just
> because you have arrays. So don't equate functions returning pointers with
> functions returning arrays in Fortran.
It has been my experience - which includes much mixed-language programming -
that Fortran and C arrays are very similar. Both C and Fortran actually
return the address of the first element when returning an array. (One very
annoying problem, however, is that while in Fortran A(3) when returned
returns an address and in C/C++ A[2] when returned returns a copy of the
element. A is an array.)
> (Though allocatables are hobbled enough prior to the f95 TR that you end
> up using pointers as a workaround a lot more often than desirable;
> hopefully, such workarounds will gradually fade away in the future).
>
>> Rather than C/C++ like pointers, are pointers in Fortran 90 more similar
>> to references and reference types in C#?
>
> I don't know boo about C#, but I've been told that F90 pointers are
> somewhat like Java reference types, so if C# ones are anything similar,
> that might also be a reasonable comparison.
C# and Java garbage collect. Visual Basic reference counts. C/C++ does
neither. Anything allocated has to be deallocated. I hate to admit it but I
am not sure what Fortran does. If this is not specified in the standard than
something is wrong.
>
> --
> Richard Maine | Good judgment comes from experience;
> email: my first.last at org.domain| experience comes from bad judgment.
> org: nasa, domain: gov | -- Mark Twain
.
- Follow-Ups:
- Re: Fortran and .NET (C#)
- From: James Van Buskirk
- Re: Fortran and .NET (C#)
- From: Richard E Maine
- Re: Fortran and .NET (C#)
- References:
- Fortran and .NET (C#)
- From: apm
- Re: Fortran and .NET (C#)
- From: Richard Maine
- Fortran and .NET (C#)
- Prev by Date: Re: Does this string processing work for you?
- Next by Date: Re: Fortran and .NET (C#)
- Previous by thread: Re: Fortran and .NET (C#)
- Next by thread: Re: Fortran and .NET (C#)
- Index(es):
Relevant Pages
|