Re: Fortran and .NET (C#)
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Tue, 27 Sep 2005 16:11:58 -0600
"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
.
- Follow-Ups:
- Re: Fortran and .NET (C#)
- From: Mr Hrundi V Bakshi
- Re: Fortran and .NET (C#)
- References:
- Fortran and .NET (C#)
- From: apm
- Re: Fortran and .NET (C#)
- From: Richard Maine
- Re: Fortran and .NET (C#)
- From: apm
- Fortran and .NET (C#)
- Prev by Date: Re: Fortran and .NET (C#)
- 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
|