Original question was:
> I have to mix F77 and C code (calling F77 procedures from C), and I'm a
> little bit lost. The F77 library has parameters like:
>
> subroutine imopen (f77nam, acmode, im, ier)
> integer acmode
> integer im
> integer ier
> character*(*) f77nam
>
> I don't really know what to pass. Sometimes integers are passed by
> reference, sometimes as values. As for the string, I don't know. It seems
> that I pass a char *, and a string length as a 5th parameter.
> So: what are the conventions? Is it documented somewhere? Is there
> a library that would provide the conversions? VMS used to have it when
> I did something like this.
> The primary goal is to do it under DUnix, but portability is a (minor)
> issue here. I can't change the fortran interface, but have full control
> over the C code. I also have 1 dimensional arrays (int/real/double).
The problem was that I did not use the '-taso' flag, which cured my
problem.
Some of the answers:
-----------------------
Sender: lee_at_rtp3.med.utah.edu
If you have multiple strings, the length of the string has to be passed
at the end of the parameter list. For example,
many_string_call_ (char *str1, char *str2, char *str3, ...., int
str1_len, int str2_len, int str3_len, ...)
-----------------------
From: "Charles C. H. Jui" <jui_at_booboo.physics.utah.edu>
Rules of thumb for mixing FORTRAN and C
(1) on most UNIX platforms, the compiler changes all FORTRAN symbols
(i.e. subroutine names, function names, and names of common blocks)
to lower case only, and appends an underscore "_" after it
e.g. a function xxx in FORTRAN is to be accessed as "xxx_" from "C"
a "C" routine whose name does not end in "_" cannot be called from FORTRAN
(2) a common block and an instance of a global structure with the same
name (i.e. differeing only by "_") share the same starting address
(3) FORTRAN always passes variables and arrays by "starting address"
(4) by default "C" passes variables by value, and arrays by address
-----------------------
I think these two answers cover all bases (thanks University of Utah).
Thanks to:
From: Wing-lok Lee <lee_at_rtp3.med.utah.edu>
From: Hans Kowallik <hans_at_physics.orst.edu>
From: "Charles C. H. Jui" <jui_at_booboo.physics.utah.edu>
From: rioux_at_ip6480nl.ce.utexas.edu (Tom Rioux)
From: Ken Teh <teh_at_chinook.phy.anl.gov>
From: aa_at_mr.picker.com (Anthony Apicella)
(and all others, whose mail is still coming),
Gyula Szokoly
Received on Fri Oct 11 1996 - 21:39:45 NZDT