delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/09/09:45:55

From: Christoph Kukulies <kuku AT gilberto DOT physik DOT RWTH-Aachen DOT DE>
Message-Id: <199705091345.PAA01610@gil.physik.rwth-aachen.de>
Subject: Re: Calling Fortran code from a C program
In-Reply-To: <337312EF.2B7@hercules.elte.hu> from Dobler Ervin at "May 9, 97 02:05:03 pm"
To: dobler AT hercules DOT elte DOT hu
Date: Fri, 9 May 1997 15:45:35 +0200 (MEST)
Cc: djgpp AT delorie DOT com
Reply-To: Christoph Kukulies <kuku AT gilberto DOT physik DOT RWTH-Aachen DOT DE>
MIME-Version: 1.0

> I have a package of routines written in Fortran77, and I would like to
> call them from a C program. I'm using GNU's g77 and GNU C.
> If there is somebody who can answer my questions I would be very
> grateful.
> My questions are:
> 1. How can I specify the appropriate calling convention?

You cannot specify it. It is a given fact and there is only one,
call by reference:

  C function calls fortran:

main()
{
  int i=1;
  double f=2.0;
  char *string1="Hello";
  char *string2=" World";
  foo_ ( &i,&f,string1, string2,len1,len2)
}

Fortran :

        subroutine foo(i,f,str1,str2)
        integer*4 i
        real*8 f
        character*(*) str1,str2
        write(*,*)i,f,str1,str2
        return
        end

f77 -c f.f
gcc -c c.c
gcc -o c c.o f.o -lf2c
go32 c

It should work under g77 as well as under f77 (f2c) 


> 2. What type of name mangling does the f77 compiler use?

fortran functions get an underscore appended. 

> 3. Should I have indicate something in the fortran code as well?

No. We are not in the Microsoft world ("Power" Fortran).

> 4. What are the appropriate gcc command-line switches for .f and .c
> files?
> 5. I would like to access variables, arrays in the fortran code as well.
> Does it differs from accessing functions?

I don't think I understand this question.


> 
> Please send your answers at 'dobler AT hercules DOT elte DOT hu'.
> Thanks in advance
> 
> Ervin Dobler
> Technical University of Budapest, Department of Atomic Physics.
> 

--
Chris Christoph P. U. Kukulies kuku AT gil DOT physik DOT rwth-aachen DOT de

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019