Re: gfortran and the family of fortran array types
- From: "Jugoslav Dujic" <jdujic@xxxxxxxxx>
- Date: Thu, 28 Aug 2008 10:18:59 +0200
Richard Maine wrote:
| relaxmike <michael.baudin@xxxxxxxxx> wrote:
|
|| The fortran 90 array is declared as :
||
|| real(kind=C_FLOAT), dimension(:,:), allocatable, target :: mat
||
|| To be manageable by the C routine, a conversion must be done so that
|| only the base_addr field is passed to the C routine.
|
| That is not so. Of course, prior to f2003, the standard didn't provide
| any way at all to call C (or have the above C_FLOAT constant), but that
| aside, there would be no problems at all with passing the above array to
| C. It does *NOT* require the use of C_LOC.
|
| You appear to be assuming that all arrays are inherently passed as dope
| vectors, which is not so. I suspect that the confusion partly arises
| from looking at argument passing conventions exactly backwards. To see
| how an array is passed to a particular subroutine, you do *NOT* start
| out by looking at the array in question. You start out by looking at the
| interface of the subroutine. That's what defines the expected passing
| mechanism.
But other than that, his post was pretty much spot on.
From a practical compiler implementation standpoint, interfacing F90 with C(subtleties like CHARACTER aside) works pretty much as interfacing F90 with
F77. Neither C nor F77 know about assumed-shape, allocatable or pointer
arguments (and associated dope vector) -- all they "know" is an address of
the first element. In C it is expressed more explicitly with * operator,
while in F77 one uses an assumed-size (or explicit-shape) dummy.
Thus, (attempting to express Richard's point somewhat differently): a F90
compiler may (but need not) mantain a dope vector internally, as a bookkeeping
device; but whether it will pass it or not depends *only* on the called routine
interface/prototype. If it's a f90 assumed-shape/allocatable/pointer argument
(which, remind you, need an /explicit interface/), it will pass it (and
create one on the fly if necessary, such as in CALL FOO(A(1:8:2)) or
CALL Foo([12,8,2008,12,53]) ). Otherwise, it will "just" pass the address.
With F2003 C interop, C_LOC does that conversion explicitly and is
guaranteed to be portable. Before that, one would just pass the array
(assumed-size assumed by compiler), relying on both compilers to do
the right thing (they would most often do, but it wasn't guaranteed
by the Standard).
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.
- Follow-Ups:
- Re: gfortran and the family of fortran array types
- From: Richard Maine
- Re: gfortran and the family of fortran array types
- References:
- Re: gfortran and the family of fortran array types
- From: relaxmike
- Re: gfortran and the family of fortran array types
- From: relaxmike
- Re: gfortran and the family of fortran array types
- From: Richard Maine
- Re: gfortran and the family of fortran array types
- Prev by Date: Re: Project dependency of CVF 6.6c
- Next by Date: Re: Surprise
- Previous by thread: Re: gfortran and the family of fortran array types
- Next by thread: Re: gfortran and the family of fortran array types
- Index(es):
Relevant Pages
|