V10/cmd/f2c/doc/sn

.EQ
define dollar % "\f(CW$\fP" %
delim $$
define f2c % "f\|2c" %
define F2c % "F\^2c" %
define libF77 % "libF77" %
define libI77 % "libI77" %
define LibF77 % "LibF77" %
define LibI77 % "LibI77" %
.EN
.TL
Availability of \f(BIf\|2c\fB \(em a Fortran to C Converter
.AU
S. I. Feldman
.AI
Bellcore
Morristown, NJ 07960
.AU
D. M. Gay
.AI
.MH
.AU
M. W. Maimone
.AI
Carnegie-Mellon University
Pittsburgh, PA 15213
.AU
N. L. Schryer
.AI
.MH
.AB \ 
.AE
.PP
We have produced a program that automatically converts ANSI
standard Fortran 77
.[ [
ANSI FORTRAN 1978
.]]
to C
.[ [
Kernighan Ritchie 1988
.]].
It has converted many Fortran programs
without manual intervention; it is easily available \(em free
of charge (and of warranty) \(em by electronic mail and $ftp$.
.PP
Automatic conversion of Fortran 77
is desirable for
several reasons.  Sometimes it is useful to run a
well-tested Fortran program on a machine that has a C
compiler but no Fortran compiler.  At other times, it
is convenient to mix C and Fortran.  Some things are
impossible to express in Fortran 77 or are harder
to express in Fortran than in C
(e.g. storage management, some character operations,
arrays of functions, heterogeneous data structures,
and calls that depend on the operating system),
and some programmers simply prefer C to Fortran.
There is a large body of well tested
Fortran source code for carrying out a wide variety of
useful calculations, and it is sometimes desirable to
exploit some of this Fortran source in a C environment.
Many vendors of computing platforms and operating systems
provide some way of mixing C and Fortran, but
the details vary from system to system.
Automatic Fortran to C conversion lets one create a
.I portable
C program that exploits Fortran source code.
.PP
A side benefit of automatic Fortran 77 to C conversion is that
it allows tools like
.I lint
\ 
.[[
v101
.]]
to provide Fortran 77 programs with some of the consistency
and portability checks that the Pfort Verifier
.[ [
Ryder 1974
.]]
made available to Fortran 66 programs.
.PP
Starting from Feldman's original $f77$ compiler
.[ [
Feldman Weinberger Portable Fortran
.]]
(the original UNIX\u\(rg\d Fortran 77 compiler),
we created a program called $f2c$ that converts
Fortran 77 source code into C.
Our report
.[ [
Feldman Gay Maimone Schryer
.]]
describes $f2c$'s conversions in considerable detail;
the purpose of this note is to point out the availability
both of our report and of the source for $f2c$ itself.
On request, we are happy to send out paper copies of the report.
You can also obtain a Postscript version of it by electronic
mail by sending the message
.ce
\f(CWsend f2c.ps from f2c\fR
to \f(CWnetlib@research.att.com\fR.  Source for both $f2c$
and the support libraries assumed by the C it produces
is available by electronic mail and by $ftp$.  For details,
send the electronic-mail message
.ce
\f(CWsend index from f2c\fR
to  \f(CWnetlib@research.att.com\fR.  You can also $ftp$ to
\f(CWresearch.att.com\fR; in subdirectory \f(CWdist/f2c\fR you
will find a copy of the \f(CWindex\fR file and of source for
$f2c$ and its support libraries.
(As of this writing, 520 different people have
obtained $f2c$ source from
.I netlib ,
i.e., by electronic mail,
and 1093 have obtained it by $ftp$.)
.PP
We have used $f2c$ to convert various large programs and
subroutine libraries to C automatically (i.e., with no manual intervention);
these include the \s-2PORT3\s+2 subroutine library
.[ [
port3
.]]
(\s-2PORT1\s+2 is described in
.[ [
Fox Hall Schryer Algorithm 1978
.]
.[
Fox Hall Schryer port 1978
.]]),
MINOS
.[ [
Murtagh Saunders 1987
.]],
and Schryer's floating-point test
.[ [
Schryer floating
.]].
In addition to our own testing, we have been helped by feedback
from many people and by observing $f2c$'s behavior on some 33 megabytes
of Fortran submitted to $netlib$'s experimental ``\f(CWexecute f2c\fR''
service; this feedback and our observations have led us to isolate
and repair numerous bugs and to extend $f2c$ in various ways.
.PP
Although we tried to make $f2c$'s output reasonably readable,
our goal of strict compatibility with $f77$ implies some nasty
looking conversions.  Input/output statements, in particular,
generally get expanded into
a series of calls on routines in $libI77$ ($f77$'s I/O library),
and complex arithmetic often results in messy C.
Thus the output of $f2c$ may be difficult
to maintain as C, and it may be more sensible to maintain the original
Fortran, translating it anew each time it changes.  Some commercial
vendors of conversion services, e.g.,
those listed in an appendix to our report,
seek to perform translations yielding C that one
might reasonably maintain directly; in general, these translations
require some manual intervention.
.PP
$F2c$ optionally emits special files called
.I prototype
files that summarize the calling sequences of
the translated subprograms.
A side benefit of $f2c$ is that it can read prototype
files and check the consistency of calling sequences
across files.  We have found this to be a useful debugging aid.
Use of prototypes is slightly more convenient than invoking
.I lint ,
but
.I lint
warns of other possible errors, such as variables that may be
referenced before they are set.

.ce
REFERENCES
.LP
.so tmac.sdisp1
.[
$LIST$
.]