Re: Fortran and .NET (C#)



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). Even if you are an expert, the odds are high of screwing it up and leaking memory or having other bugs. And if one is a novice, well, one pretty much abandons all hope of a bug-free program if one uses functions that return pointers. I recommend using subroutines for all cases where a pointer needs tobe returned (return it via an argument).

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. (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.


--
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
.



Relevant Pages

  • Re: Array comparison
    ... > Deep and recursive. ... the pointers and comparing their referents instead of comparing the ... >> arrays, then I think you also need to argue against assigning arrays. ... semantics (notably, reference counting). ...
    (alt.comp.lang.borland-delphi)
  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (comp.lang.java)
  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (comp.lang.cpp)
  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (sci.crypt)
  • Re: INTERFACE problem
    ... I have an integer at Fortran side, pass it by reference to C function, treat here as pointer, allocate memory and this C-pointer at Fortran side now is an integer which has represents address allocated at C side. ... I did something like this many years ago to allow dynamic allocation ... Then it was converted into a subroutine with the arrays and ... it called the sub by way of Pascal with those "pointers". ...
    (comp.lang.fortran)