Problems with f2c

lacey@cps.msu.edu
Wed, 29 Jul 1992 04:23:15 GMT

          From comp.compilers

Related articles
Problems with f2c lacey@cps.msu.edu (1992-07-29)
Re: Problems with f2c henry@zoo.toronto.edu (1992-07-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: lacey@cps.msu.edu
Organization: Compilers Central
Date: Wed, 29 Jul 1992 04:23:15 GMT
Keywords: C, Fortran, question

I am unhappy with how f2c hands PARAMETER statements, and I am wondering
if there is anybody out there that has written a patch to make it somewhat
more sane, if such a patch could be written easily, and if neither of
those, if anybody has a suggestion on how to work around it. The problem
is, if you have:
PARAMETER (MAXXI=100)
...
INTEGER XI(MAXXI)


it gets translated to:
integer xi[100];


What I would _like_ to see is:


#define MAXXI 100


integer xi[MAXXI];


The project I am currently working on consists of building an X-windows
interface onto an old Fortran program, which is converted to C with f2c,
and then portions are modified. There are 55,000 lines of Fortran, in
around 45 files, along with another 12 common block files, in which the
PARAMETER statements appear. The optimum result would be for each .F file
to be translated to a .c file, each .CBK (common block) file translated
into a .c file (this can be done with the -E option, I think it is), and
then a .h file created fopr each common block with the #define's for
PARAMETER statements, along with extern's for all of the common block
data.


I can't think of a work-around that actually works. One approach I tried
was to replace each of the values in a PARAMETER statement with some
unique prime number, and then use 'sed' to replace occurances of the value
with a string. This didn't work because of the fact that these parameters
are often multiplied together by f2c, and the result is a different
number, which often contains a substring of another number. I could get
this to work if I could figure out how to make sed replace a string of
digits, strictly surrounded by non-digits, with a string (i.e. not replace
sub-strings of digits). The parameters also, of course, show up in the
Fortran source code (if they didn't I could solve things pretty easily, by
hand).


Any help would be appreciated. Please send e-mail rather than posting.


Thanks,


Mark M. Lacey
[lacey@cps.msu.edu]
[Try sed 's/\([^0-9]\)1234\([^0-9]\)/\1 MAXXI \2/' -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.