|
|
1.1 ! root 1: .EQ ! 2: define f2c % "f\|2c" % ! 3: define F2c % "F\^2c" % ! 4: define libF77 % "libF77" % ! 5: define libI77 % "libI77" % ! 6: .EN ! 7: .SH ! 8: Suggested rewordings... ! 9: ! 10: Bottom of p. 4: ! 11: .PP ! 12: A Fortran routine containing $n$ \f(CWentry\fR statements ! 13: is turned into $n^+^2$ C functions, a big one containing ! 14: the translation of everything but the \f(CWentry\fR statements, ! 15: and $n^+^1$ little ones that invoke the big one. Each little ! 16: one passes a different integer to the big one to tell ! 17: it where to begin; the big one starts with a switch ! 18: that branches to the code for the appropriate entry. ! 19: The Fortran program ! 20: ! 21: .SH ! 22: Add to end of \(sc3: ! 23: .PP ! 24: $F2c$ assumes the services of the support libraries $libF77$ and $libI77$. ! 25: Among other things, libF77 contains a C main routine that arranges ! 26: for files to be closed automatically when the Fortran program stops ! 27: and arranges for an error message to be printed if a floating-point ! 28: exception occurs. The C main routine invokes the Fortran main program, ! 29: which is called ! 30: .CW MAIN_\|_ . ! 31: ! 32: ! 33: .SH ! 34: Revision of \(sc 4: ! 35: ! 36: ! 37: .SH ! 38: 4. MAINTENANCE and PORTABILITY ! 39: .PP ! 40: Although we have tried to make $f2c$'s output reasonably readable, ! 41: our goal of strict compatibility with $f77$ implies some nasty ! 42: looking conversions. Input/output statements, in particular, ! 43: generally get expanded into ! 44: a series of calls on routines in $libI77$, $f77$'s I/O library. ! 45: Thus the C output of $f2c$ would probably be something of a nightmare ! 46: to maintain as C; it would be much more sensible to maintain the original ! 47: Fortran, translating it anew each time it changed. Some commercial ! 48: vendors seek to perform translations yielding C that one ! 49: might reasonably maintain directly; these translations generally ! 50: require some manual intervention. ! 51: . \"Appendix B lists the vendors ! 52: . \"of whom we are aware; omitted vendors are invited to inform us of ! 53: . \"their existence, so we may include them in updated versions of ! 54: . \"Appendix B. ! 55: .PP ! 56: The Pfort Verifier ! 57: .[ [ ! 58: Ryder 1974 ! 59: .]] ! 60: was a useful tool for catching errors in calling sequences ! 61: of Fortran 66 programs. $F2c$ combined with $cyntax(1)$ or $lint(1)$ ! 62: .[ [ ! 63: UNIX ninth edition manual ! 64: .]] ! 65: provides a similar capability for Fortran 77 programs. ! 66: .PP ! 67: There are two portability issues in using $f2c$: ! 68: the portability of the converter $f2c$ itself ! 69: and that of the C programs it creates. ! 70: .PP ! 71: The converter itself is reasonably portable and has run successfully on Apollo, ! 72: Cray, IBM, MIPS, SGI, Sun and DEC VAX equipment. ! 73: However, we shall see that the C it produces may not be portable due to ! 74: subtle storage management issues in Fortran 77. ! 75: In any case, the C output of $f2c$ will run fine, at least if ! 76: the \f(CW\(miW\fIn\fR option (see the Appendix) is used to set the ! 77: number of characters per word correctly, and if C ! 78: .CW double ! 79: values may fall on an odd-word boundary. ! 80: .PP ! 81: The Fortran 77 standard says that \f(CWComplex\fP and \f(CWDouble Precision\fP ! 82: objects occupy two ``units'' of space while other non-character data types ! 83: occupy one ``unit.'' ! 84: It may be necessary to edit the header file ! 85: .CW f2c.h ! 86: to make these assumptions hold, if possible. ! 87: On the Cray, for example, ! 88: .CW float ! 89: and ! 90: .CW double ! 91: are the same C types, and Fortran double precision, if ! 92: available, would correspond to the C type ! 93: .CW "long double" . ! 94: In this case, changing the definition of ! 95: .CW doublereal ! 96: in ! 97: .CW f2c.h ! 98: from ! 99: .P1 ! 100: typedef double doublereal; ! 101: .P2 ! 102: to ! 103: .P1 ! 104: typedef long double doublereal; ! 105: .P2 ! 106: would be appropriate. For the Think C compiler on the ! 107: Macintosh, on the other hand, this line would need to become ! 108: .P1 ! 109: typedef short double doublereal; ! 110: .P2 ! 111: .PP ! 112: If your C compiler predefines symbols that could clash with ! 113: translated Fortran variable names, then you should also ! 114: add appropriate ! 115: .CW #undef ! 116: lines to ! 117: .CW f2c.h . ! 118: The current default ! 119: .CW f2c.h ! 120: provides the following ! 121: .CW #undef ! 122: lines: ! 123: .P1 ! 124: #undef cray ! 125: #undef gcos ! 126: #undef mc68010 ! 127: #undef mc68020 ! 128: #undef mips ! 129: #undef pdp11 ! 130: #undef sgi ! 131: #undef sparc ! 132: #undef sun ! 133: #undef sun2 ! 134: #undef sun3 ! 135: #undef sun4 ! 136: #undef u370 ! 137: #undef u3b ! 138: #undef u3b2 ! 139: #undef u3b5 ! 140: #undef unix ! 141: #undef vax ! 142: .P2 ! 143: .PP ! 144: As an extension to the Fortran 77 Standard, $f2c$ ! 145: allows noncharacter variables to be initialized with character ! 146: data. This extension is inherently nonportable, as the number ! 147: of characters storable per ``unit'' varies from machine to machine. ! 148: Since 32 bit machines are the most plentiful, $f2c$ ! 149: assumes 4 characters per Fortran ``unit'', but this assumption ! 150: can be overridden by the \f(CW\(miW\fIn\fR command-line option. ! 151: For example, ! 152: .CW \(miW8 ! 153: is appropriate for C that is to be run on Cray computers, ! 154: since Crays store 8 characters per word. ! 155: An example is helpful here: the Fortran ! 156: .P1 ! 157: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/data.holl.f ! 158: .P2 ! 159: turns into ! 160: .P1 ! 161: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/data.holl.c ! 162: .P2 ! 163: (Some use of ! 164: .CW i , ! 165: e.g. ``\(CWi=1\fR'', is necessary or $f2c$ ! 166: will see that ! 167: .CW i ! 168: is not used and will not initialize it.) If the target ! 169: machine were a Cray and the string were ! 170: .CW 'abcdefgh' ! 171: or \f(CW"abcdefhg"\fR, ! 172: then the Fortran would run fine, but the C produced by $f2c$ would only ! 173: store \f(CW"abcd"\fR ! 174: in i, $4$ being the default number of characters per word. ! 175: The $f2c$ command-line option ! 176: .CW \(miW8 ! 177: gives the correct initialization for a Cray. ! 178: .PP ! 179: The initialization above is clumsy, using $4$ separate characters. ! 180: Using the option ! 181: .CW -A , ! 182: for ANSI, produces ! 183: .CW "abcd" ; ! 184: see the Appendix. ! 185: .PP ! 186: The above examples explain why the Fortran 77 standard excludes ! 187: Hollerith data statements: the number of characters per word is ! 188: not specified and hence such code is not portable even in Fortran. ! 189: (Fortran that conservatively assumes only $1$ or $2$ characters per word is ! 190: portable but messy). ! 191: .PP ! 192: Some systems require that C values of type ! 193: .CW double ! 194: be aligned on a double-word boundary. Fortran ! 195: .CW common ! 196: and ! 197: .CW equivalence ! 198: statements may require some C ! 199: .CW double ! 200: values to be aligned on an odd-word boundary. ! 201: On systems where double-word alignment is required, ! 202: C compilers pad structures, if necessary, to arrange ! 203: for the right alignment. Often such padding has no effect on ! 204: the validity of $f2c$'s ! 205: translation, but using ! 206: .CW common ! 207: or ! 208: .CW equivalence , ! 209: it is easy to contrive examples in which ! 210: the translated C works incorrectly. ! 211: $F2c$ issues a warning message when double-word alignment may ! 212: cause trouble, but it makes no attempt to circumvent this trouble. ! 213: .PP ! 214: Long decimal strings in \f(CWdata\fP statements are passed to C unaltered. ! 215: However, expressions involving long decimal strings are rounded ! 216: in a machine dependent manner. ! 217: The Fortran ! 218: .P1 ! 219: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/longpow.f ! 220: .P2 ! 221: yields the C ! 222: .P1 ! 223: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/longpow.c ! 224: .P2 ! 225: when $f2c$ runs on a VAX 8550. ! 226: .PP ! 227: ANSI C compilers require that all but one instance of any entity with external scope, ! 228: such as the \f(CWstruct\fPs into which $f2c$ translates \f(CWcommon\fP, ! 229: be declared \f(CWextern\fP and that exactly one declaration should define the entity, ! 230: i.e., not be declared \f(CWextern\fP. ! 231: Older C compilers have no such restriction. ! 232: To be compatible with ANSI usage, the $f2c$ ! 233: command-line option ! 234: .CW -ec ! 235: causes the \f(CWstruct\fP corresponding ! 236: to an uninitialized \f(CWcommon\fP region to be declared \f(CWextern\fP ! 237: and makes a ! 238: .CW union ! 239: of all successive declarations of that ! 240: \f(CWcommon\fP region into a defining declaration placed in a file with the ! 241: name \f(CWcname_com.c\fR, where ! 242: .CW cname ! 243: is the name of the \f(CWcommon\fP region. ! 244: For example, the Fortran ! 245: .P1 ! 246: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/mainsam.f ! 247: .P2 ! 248: when converted by \f(CWf2c -ec\fP produces ! 249: .P1 ! 250: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/mainsam.c ! 251: .P2 ! 252: as well as the file \f(CWcmname_com.c\fR: ! 253: .P1 ! 254: .so /n/pipe/z7/nlsw7/f77.c/doc/tm/cmname_com.c ! 255: .P2 ! 256: The files ! 257: .CW *_com.c ! 258: may be compiled into a library ! 259: against which one can load to satisfy overly fastidious ANSI C compilers. ! 260: ! 261: ! 262: .[ ! 263: $LIST$ ! 264: .] ! 265: ! 266: ! 267: \fISource for the above is ! 268: \f(CW/n/pipe/usr/dmg/f2c/doc/revs\fR
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.