[comp.lang.c] "c" calling Fortran, and Fortran calling "c"

alf@edstip.EDS.COM (John Hamill) (09/19/89)

I would like to know how I can combine Fortran and "c" programs.  

If you know of a good book that gives examples could you send me the name.

If you have an example, could you send me it.

I am using a SUN with BSD 4.2 Unix.

Thank you in advance.


-- 
/~~|  |\  |\   John W. Hamill, EDS `""""""" UUCP: ...!uunet!edsews!edstip!alf 
|  |  |/  |/   1400 N. Woodward Ave (. (. >       alf@edstip.EDS.COM          
\__\_/^\_/|\_/ Bloomfield Hills,            Voice:(313)645-4524  Fax:645-4824 
          \/   MI 48013  * The above are my views only!!             

pierre@rhi.hi.is (Kjartan Pierre Emilsson) (09/21/89)

From article <795@edstip.EDS.COM>, by alf@edstip.EDS.COM (John Hamill):
> 
> I would like to know how I can combine Fortran and "c" programs.  
> 
> If you know of a good book that gives examples could you send me the name.
> 
> If you have an example, could you send me it.
> 
> I am using a SUN with BSD 4.2 Unix.
> 
> Thank you in advance.

It depends on the compilers you are using for fortran and C.  On a HP-9000
the process is totally invisible, i.e you just call the fortran function from
you C program:

					external some_fortran_function;
					.
					.
					.
					
					some_fortran_function(arguments)
					
And the same if you call a c function from a fortran program.  Just remember
that all arguments to a fortran function called from C should be pointers,
and that all argument declarations in a c function called from fortran should
be pointers.  (The only limitation are function pointers, which you cannot
send easily.  Structures can also be a mess).

Compile each object with the corresponding compiler, and then link the objects
together using your favorite linker (Use for example the compiler to which 
the main program corresponds).

For other systems, you may have to build a so-called jacket routine, which
translates the function name in C to the corresponding function name in fortran
and inversely.  Check your compilers system manual.

						-Kjartan
						
---------------------------------------------------------------------------
Kjartan Pierre Emilsson
Science Institute of the University of Iceland
Dunhaga 3
Reykjavik
ICELAND      e-mail: pierre@krafla.rhi.hi.is