F2C(1)
๐ F2C(1) โ like, the iconic Fortran-to-C converter, bestie ๐
okay so picture this: you've got a dusty old General Commands Manual page called f2c, and it's literally your glow-up guide for dragging Fortran 77 kicking and screaming into the C/C++ world. no cap, this thing ate. let's get into it โจ
๐ธ NAME ๐ธ
f2c โ converts Fortran 77 โ C or C++ ๐ฆ
๐ SYNOPSIS ๐
f2c [ option ... ] file ...
๐ DESCRIPTION ๐
so f2c takes Fortran 77 source code from files whose names end in .f or .F and turns it into C (or C++) source files in the current directory, with .c swapped in for the final .f or .F. slay ๐
and if you don't name any Fortran files at all? it reads Fortran from standard input and writes C on standard output. main character energy, honestly.
oh and โ file names ending in .p or .P are treated as prototype files, exactly the kind thing that option -P produces, and those get read first. iykyk ๐ซถ
the options below have the same meaning as in f77(1):
โจ the options that are giving f77(1) energy โจ
-Cโ compile the code so subscripts get checked against the declared array bounds. safety first, bestie ๐ก๏ธ-I2โ rendersINTEGERandLOGICALasshort, andINTEGER*4aslong int. it assumes the defaultlibF77andlibI77, meaning onlyINTEGER*4variables (and noLOGICALvariables) are allowed in INQUIREs. also โ option-I4confirms the default rendering ofINTEGERaslong int. ๐-I8โ assumes 8-byte integer and logical, 4-byteREAL, 8-byte double precision and complex, and 16-byte double complex variables. heads up though: appropriate changes tof2c.hmay be needed ๐ญ-Idirโ looks for a non-absolute include file first in the directory of the current input file, then in the directories you specified with-Ioptions (one directory per option). but real talk: options-I2,-I4, and-I8have precedence, so like โ if you mean a directory named2, you gotta say-I./2๐ซ-onetripโ compiles DO loops so they're performed at least once if reached. (because Fortran 77 DO loops aren't performed at all if the upper limit is smaller than the lower limit. yes, that's the vibe. that's the rule.) ๐-Uโ honors the case of variable and external names. and Fortran keywords must be in lower case, no exceptions ๐-uโ makes the default type of a variableundefinedinstead of using the default Fortran rules ๐ป-wโ suppresses all warning messages. or, if the option is-w66, just the Fortran 66 compatibility warnings. pick your peace ๐คซ
๐ฆ the options that are so f2c, nobody else has them ๐ฆ
-Aโ produces ANSI C. and that's the default, starting20020621btw. for old-style C, use option-K. โญ-aโ makes local variablesautomaticrather thanstatic... unless they show up in a DATA, EQUIVALENCE, NAMELIST, or SAVE statement. exceptions, always exceptions ๐-C++โ outputs C++ code. periodt ๐-cโ includes the original Fortran source as comments ๐ฌ-cdโ does not recognizecdabs,cdcos,cdexp,cdlog,cdsin, andcdsqrtas synonyms for the double complex intrinsicszabs,zcos,zexp,zlog,zsin, andzsqrtrespectively, and also does not recognizedrealas a synonym fordble. nope. not today. ๐ซ-cfโ doesn't report the current.ffile, except in error messages ๐ค-ddirโ writes.cfiles into directory dir instead of the current directory ๐-Eโ declares uninitialized COMMON to beExtern(overridably defined inf2c.hasextern) ๐ฅ-ecโ places uninitialized COMMON blocks in separate files:COMMON /ABC/appears in fileabc_com.c. and option-e1cbundles those separate files into the output file, with comments that give an unbundlingsed(1)script. so organized of her ๐-extโ complains aboutf77(1)extensions ๐ค-fโ assumes free-format input: accepts text after column 72 and does not pad fixed-format lines shorter than 72 characters with blanks ๐-72โ treats text appearing after column 72 as an error ๐จ-gโ includes the original Fortran line numbers in#linelines ๐ข-hโ emulates Fortran 66's treatment of Hollerith: tries to align character strings on word boundaries (or, if the option is-hd, on double-word boundaries) ๐ง-i2โ similar to-I2, but it assumes a modifiedlibF77andlibI77(compiled with-Df2c_i2), soINTEGERandLOGICALvariables may be assigned by INQUIRE and array lengths are stored inshort ints ๐ฉณ-i90โ does not recognize the Fortran 90 bit-manipulation intrinsicsbtest,iand,ibclr,ibits,ibset,ieor,ior,ishft, andishftc๐ซ-krโ uses temporary values to enforce Fortran expression evaluation where K&R (first edition) parenthesization rules allow rearrangement. and if the option is-krd, it uses double precision temporaries even for single-precision operands ๐-Pโ writes afile.Pof ANSI (or C++) prototypes for definitions in each inputfile.forfile.F. when reading Fortran from standard input, it writes the prototypes at the beginning of standard output. and option-Psimplies-Pand gives exit status4if rerunningf2cmay change prototypes or declarations ๐-pโ supplies preprocessor definitions to make common-block members look like local variables ๐ญ-Rโ does not promote REAL functions and operations to DOUBLE PRECISION. option-!Rconfirms the default, which imitatesf77๐-rโ casts REAL arguments of intrinsic functions and values of REAL functions (including intrinsics) to REAL ๐ช-r8โ promotes REAL to DOUBLE PRECISION, and COMPLEX to DOUBLE COMPLEX โฌ๏ธ-sโ preserves multidimensional subscripts. suppressed by option-C. (rude, but okay) ๐-Tdirโ puts temporary files in directory dir ๐๏ธ-trapuvโ dynamically initializes local variables โ except those appearing in SAVE or DATA statements โ with values that may help find references to uninitialized variables. for example, with IEEE arithmetic, it initializes local floating-point variables to signaling NaNs. lowkey genius fr fr ๐ต๏ธ-w8โ suppresses warnings when COMMON or EQUIVALENCE forces odd-word alignment of doubles ๐คซ-Wnโ assumes n characters/word (default4) when initializing numeric variables with character data ๐ค-zโ does not implicitly recognize DOUBLE COMPLEX ๐ค-!bsโ does not recognize backslash escapes (\",\',\0,\\,\b,\f,\n,\r,\t,\v) in character strings ๐ซ-!cโ inhibits C output, but still produces-Poutput ๐คฏ-!Iโ rejects include statements ๐-!i8โ disallowsINTEGER*8, or, if the option is-!i8const, permitsINTEGER*8but does not promote integer constants toINTEGER*8when they involve more than 32 bits ๐ข-!itโ doesn't infer types of untyped EXTERNAL procedures from use as parameters to previously defined or prototyped procedures ๐ง-!Pโ does not attempt to infer ANSI or C++ prototypes from usage ๐
and the resulting C invokes the support routines of f77; object code should be loaded by f77 or with ld(1) or cc(1) options -lF77 -lI77 -lm. the calling conventions are those of f77: see the reference below, bestie ๐ซถ
๐ FILES ๐
file.[fF]โ input file ๐ฅ*.cโ output file ๐ค/usr/include/f2c.hโ header file ๐/usr/lib/libF77.aโ intrinsic function library ๐งฎ/usr/lib/libI77.aโ Fortran I/O library ๐พ/lib/libc.aโ C library, see section 3 ๐
๐ SEE ALSO ๐
S. I. Feldman and P. J. Weinberger, A Portable Fortran 77 Compiler, UNIX Time Sharing System Programmer's Manual, Tenth Edition, Volume 2, AT&T Bell Laboratories, 1990. ๐โจ
๐ DIAGNOSTICS ๐
the diagnostics produced by f2c are intended to be self-explanatory. so like, read them. they're telling you things. ๐
๐ง BUGS ๐ง
- Floating-point constant expressions are simplified in the floating-point arithmetic of the machine running
f2c, so they are typically accurate to at most 16 or 17 decimal places ๐ญ - Untypable EXTERNAL functions are declared
int๐ซ - There is no notation for
INTEGER*8constants ๐ - Some intrinsic functions do not yet work with
INTEGER*8๐
okay that's the whole page, bestie ๐ and for the cute sign-off: this one's filed under F2C(1) in your General Commands Manual, with all that ANSI-C-by-default goodness dated back to 20020621. go forth and convert, you gorgeous nerd ๐๐ฆโจ
๐ฆ where this page comes from
- nixos 26.05: f2c 20240312
- nixpkgs unstable: f2c 20240312
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms