This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: another calling-fortran-from-C-question


Daniel Franke wrote:
> Google is not that much of help, all it reveals: "Don't do it", "Dragons 
> there" and similar =(

seems about right :-)

> Now I'd like to have a C-wrapper function to call the library entry point (I 
> did this before with code written in f77). 
> 
> The function requires arguments as this:
>    INTEGER, DIMENSION(:), INTENT(IN) :: RgType
>    REAL(kind=stnd), INTENT(IN), DIMENSION(:,:,:) :: Vertices
> 
> I learned these arrays are "assumed-shape" arrays, i.e. they can represent 
> almost anything.

They're not.  They're of deferred shape.  The distinction is important because
assumed shape arrays were already possible in Fortran 77, but deferred-shape
arrays are very different beasts: to handle them the subroutine needs to be
passed detailed information about the array, as the whole layout of the array
is variable.  See the description around trans-types.c:710 for how this is
handled in gfortran.  Unfortunately, we don't guarantee compatibility to
future versions (even though it's likely), nor do different compilers handles
this in the same way.

> In f77 I could pass a simple C-pointer to fortran routines 
> which ask for arguments as in:
>    INTEGER, DIMENSION(NumRg), INTENT(IN) :: RgType
>    REAL(kind=stnd), INTENT(IN), DIMENSION(DIM,DIM+1,NumRg) :: Vertices

This case is much simpler, because no array descriptor is needed.

> If so, I'd like to ask for some pointers to docs, sources, whatever where I 
> can find information on how gfortran implements this since I don't mind doing 
> it non-portably or platform dependent -- everythings better than 
> reimplementing that library! I just need the results ...

I guess I pointed you in the right direction then.  libgfortran/libgfortran.h
contains accessor macros for the descriptors that should make your life easier.

Hope this helps,
- Tobi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]