Re: Fortran and .NET (C#)



"apm" <Contributor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:bdg_e.24065$nq.9634@xxxxxxxxxxxxx

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

What planet are you living on? C doesn't even have arrays, at least
until C99, which seems to be about as widely implemented as f03. For
example, if you want to write a matrix multiplication function (or any
matrix manipulation function) in C, you have to either allocate an array
of pointers to its rows, point to the first element of each row, and
pass a pointer to the first element in the array of row pointers or
compute array offsets by hand, A[n*i+j] instead of A[i][j] within
the matrix manipulation function.

As far as returning an array, if you are referring to f77, the
return had to be through an argument, so that the address of the
first element would not get returned. If f90/f95, the array
could be returned through the result variable, but the shape of
the array has to be precomputable via specification expressions.
Much more than just the address of the first element must be
returned, although everything but the element values are effectively
returned in a function prologue. This technique is also leakproof
so that it can be used within expressions, unlike what would be
the case with a C function returning a pointer.

In f03 a function can return an allocatable result, which is
more general than what is possible in f95. For example, one
could return an array or character variable that contains a
line or record of input. So I'm not sure what you mean by
returning an array in C or Fortran, but I don't see that
much similarity.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


.



Relevant Pages

  • Re: Passing C structures as arguments
    ... > wondering if it is possible to pass in these arguments from a Fortran ... depending on the particular compilers. ... Be aware that Fortran pointers are *NOT* the same thing as ... You may need to play compiler-specific games for the array case, ...
    (comp.lang.fortran)
  • Re: ctypes: error passing a list of str to a fortran dll
    ... are pointers to the parameter in C, ie float*, etc ... +FortranCHARACTER and CHARACTER arrays are passed as TWO ... each element of the character array. ... The solution proposed by Jugoslav Dujic, from comp lang fortran is ...
    (comp.lang.python)
  • Re: How to construct a heterogenous list?
    ... Does anyone know how, in Fortran, to construct a linked list, the ... If you think to involve pointers to the different types, ... allocate an array to hold the result. ... I might add that compilers don't tend to do well with it. ...
    (comp.lang.fortran)
  • Re: first-class types
    ... In the subroutine or function, you have an argument list that should "match" the order and types of the actual arguments, though the names are arbitrary. ... If the actual argument is an array, the corresponding dummy argument should be an array. ... In the simples case, the dimensions (note the pleural as Fortran supports multi-dimensional arrays) should match, but there are legal ways to have the dummy array get its size from the actual arguments. ... The question was more about the internals and how variables like arrays are communicated between functions in languages that don't support pointers or the taking of an address, ...
    (comp.arch)
  • Re: array of pointers
    ... | array of pointers is neccesary more RAM memory to store these datas. ... Visual Fortran pointer descriptor format (on 32-bit ...
    (comp.lang.fortran)