Compiling Fortran and C programs



Last revision August 4, 2004

Table of Contents:
  1. cc is the C language compiler and linker
  2. f77 is the Fortran language compiler
  3. ld is the basic loader or linker program
  4. Running your executable programs

f77 is the basic Fortran language compiler

The Compaq (formerly DEC) Fortran Compiler supports the 1977 standard version of the Fortran language. Note that f77 is the typical name for a Fortran compiler in Unix and can mean different compilers on different systems. In addition to the 1977 standard Fortran syntax, the Compaq Fortran compiler accepts most extensions developed for VAX/VMS Fortran (with an appropriate option).

The Fortran language was extended with new features in 1990 and again in 1995. These two new standards are called Fortran90 and Fortran95, respectively. Many long-time Fortran programmers feel that these new standards have altered the language beyond recognition. For simple scientific programming, you should probably stick with the Fortran77 version. If you do need to compile programs written to one of the later standards, the compiler names on pangea are f90 and f95. There is a single extensive on-line manual entry for both, that can be accessed by either name. This page describes features of the f77 compiler only.

f77 basically works the same way as the cc C language compiler, except that input source files should have a .f suffix in the filename. (Use the suffix .f90 for input source files that correspond to the Fortran 90 or 95 standard.)

The C macro preprocessor is not normally called by f77. If you want to use #include and #define preprocessor statements in your Fortran programs, give the source files a .F filename suffix and f77 will first pass them through the macro preprocessor. (Use a filename suffix of .F90 for Fortran 90 or 95 source files that need to be processed by the C macro preprocessor.) Be aware that such pre-processor statements are not standard in Fortran and may not be supported on other computer systems.

Automatic linking of the final program by f77 occurs under the same circumstances as the C compiler.

Other basic options,such as selecting optimization levels or debugging information, are generally the same as cc options. The -non_shared option is also supported in Compaq's f77, with the same meaning as in cc. Especially useful options that are unique to f77 are:

-u Makes all variables default to "undefined" type if not declared. This forces you to declare all variables as integer, character, real, etc., rather than relying on the implicit rules based on first letter of the name. The advantage of this is that mis-typed variable names will be flagged by the compiler as undefined, rather than simply created as new variables. This can save you from many subtle errors.
-C Compiles code to check that subscripts are within array bounds when referencing arrays. This saves you from accidentally writing beyond array bounds at the expense of slowed execution. It is especially useful during the debugging stage.

Each Fortran compiler has many additional options for more advanced tuning of the syntax it allows or the optimizations it attempts. These options vary from compiler to compiler. You must read the on-line manual entries for descriptions and definitions. An especially useful option specific to the Compaq Fortran compiler is:
     -convert xxx
which allows you to read and write unformatted (binary) data in alternative formats used by different computer systems, as represented by a keyword after the option. Some keyword values are: big_endian, cray, ibm, and vaxd. See the on-line manual entry for details.