[comp.lang.c] the f2c program

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (08/12/90)

On the computer research.att.com is a program called "f2c". It converts
Fortran programs to, mostly, C. But it does NOT convert Fortran IO
calls to C. Instead it just invokes some mysterious io routines. I
take these to be somebody's Fortran IO runtime library - indeed, there
are linking with certain libraries. But WHOSE libraries? Would someone
with a Unix machine and NO Fortran compiler have these routines? IF
so, exactly WHOSE Unix? I can't believe that the many different Fortran
compilers out there would use the same runtime. So, whose will this
thing work with????

Doug McDonald(mcdonald@aries.scs.uiuc.edu)

henry@zoo.toronto.edu (Henry Spencer) (08/12/90)

In article <1990Aug11.202542.9891@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:
>On the computer research.att.com is a program called "f2c". It converts
>Fortran programs to, mostly, C. But it does NOT convert Fortran IO
>calls to C. Instead it just invokes some mysterious io routines. I
>take these to be somebody's Fortran IO runtime library... whose will this
>thing work with????

Also on research.att.com, in the same directory, are files named "libF77.Z"
and "libi77.Z", which might be worth investigating.
-- 
It is not possible to both understand  | Henry Spencer at U of Toronto Zoology
and appreciate Intel CPUs. -D.Wolfskill|  henry@zoo.toronto.edu   utzoo!henry

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/13/90)

In article <1990Aug11.202542.9891@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:
>On the computer research.att.com is a program called "f2c". It converts
>Fortran programs to, mostly, C. But it does NOT convert Fortran IO
>calls to C. Instead it just invokes some mysterious io routines.

Yes, you can get the source for the run-time support routines from the
same place you get the source for "f2c".

flint@gistdev.gist.com (Flint Pellett) (08/13/90)

f2c seems to do a reasonable job of translating, if you don't want to
have to work with/on the resulting C code, but only need to compile it.
The worst feature of f2c (IMHO) is that it moves all your data up to the
top of the file, leaving the comments (that explain the data) where they
were.  Example: if your Fortran code starts with 40 lines that look roughly
like this:

c	Data used as arguments to foo() function:
	data abc,def,ghi/1,2,3/
c	Data used as arguments to bar() function:
	data uvw,xyz/4,5/

it gets turned into gibberish because you end up with 20 lines of the
variables and values, followed by 20 lines of comments to explain them:
But you no longer know know what data element each comment refers to,
especially when there are variable numbers of lines of comments about
each data element/group.

A second thing that would be nice to see improved would be to have an
option to not screw up the comments.  (They seem to insist on reformatting
the comments, chopping them off to about a 70 column line, so that what
was a 1 line comment gets broken into two lines that are easily recombinable
back into 1- but who wants to have to manually recombine thousands of lines
of comments to make them readable?  I've also noted that it always breaks
the comments at a quote mark for some reason, so contractions in your
comments don't (<-like that) stay together: the line ends up like this:

/* comments don
't (<-like that) stay together: the line ends up like
this */

It ought to just take a block of comments, stick a /* line before them,
convert the leading "c" into a *, and stick a */ line after them, and
not reformat them at all, except maybe for searching for the random
/* or */ within the FORTRAN comment.
-- 
Flint Pellett, Global Information Systems Technology, Inc.
1800 Woodfield Drive, Savoy, IL  61874     (217) 352-1165
uunet!gistdev!flint or flint@gistdev.gist.com

henry@zoo.toronto.edu (Henry Spencer) (08/15/90)

In article <937@gistdev.gist.com> flint@gistdev.gist.com (Flint Pellett) writes:
>f2c seems to do a reasonable job of translating, if you don't want to
>have to work with/on the resulting C code, but only need to compile it.

Maintainable C code was specifically *not* an objective of the f2c project.
The intent is that you maintain the Fortran.  The f2c tech report comments
that producing maintainable C automatically seems to require some amount
of manual intervention even using commercial ($$$) translator programs.
-- 
It is not possible to both understand  | Henry Spencer at U of Toronto Zoology
and appreciate Intel CPUs. -D.Wolfskill|  henry@zoo.toronto.edu   utzoo!henry

rick@tmiuv0.uucp (08/16/90)

In article <1990Aug11.202542.9891@ux1.cso.uiuc.edu>, mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:
> On the computer research.att.com is a program called "f2c". It converts
> Fortran programs to, mostly, C. But it does NOT convert Fortran IO
> calls to C. Instead it just invokes some mysterious io routines. I
> take these to be somebody's Fortran IO runtime library - indeed, there
> are linking with certain libraries. But WHOSE libraries?

The mysterious routines are libf77 and libi77, available from the same
source.  I quote from the index for f2c:

    libf77  Library of non I/O support routines the generated C may need.
            Fortran main programs result in a C function named MAIN__ that
            is meant to be invoked by the main() in libf77.

    libi77  Library of Fortran I/O routines the generated C may need.
            Note that some vendors (e.g., BSC, Sun, and MIPS) provide a
            libF77 and libI77 that are incompatible with f2c -- they
            provide some differently named routines or routines with the
            names f2c expects, but with different calling sequences.
            On such systems, the recommended procedure is to merge
            libf77 and libi77 into a single library, say libf2c and
            install it where you can access it by specifying -lf2c.

The libraries and source are available from the same source as f2c.

> Doug McDonald(mcdonald@aries.scs.uiuc.edu)
-- 
----------------------------------------------------------------------------
[- O] Rick Stevens
  ?   EMail: uunet!zardoz!tmiuv0!rick -or- uunet!zardoz!xyclone!sysop
  V   CIS: 75006,1355 (75006.1355@compuserve.com from Internet)

"Reality is a crutch for people who can't handle science fiction."
----------------------------------------------------------------------------