Up to main menu         Back to Types of Files         Next: Text vs. PostScript; Viewing

Source Code vs. Executables

Computer programs written in languages such as Fortran and C must be compiled before they can be executed. The text file which we edit and call a ``program'' is referred to as the source code. A file of source code written in C should be named with the suffix .c; the name of a file of Fortran source code should end with .f90, unless it is written in the older format (instructions start after 6 blank spaces at the beginning of each line, etc.), in which case the suffix should be .f. Typical source code files are thus named invert.f90 or minimize.c.

Source code is in fact incomprehensible to the operating system, and it must be translated to a file of basic CPU instructions by a program called the compiler. The compiler for C programs is cc, and another C compiler, gcc, is usually available. The compiler for Fortran source code is f90, unless you write in the old ``column-7'' style, in which case you use f77.

The C and Fortran compilers also perform another function, unless you specify otherwise using the command-line option ``-c''; linking the program to the necessary subroutines, those that you use in your program. Fortran compilers automatically link in all the basic mathematical functions and routines which are part of standard Fortran; with C programs you have to specify the math library using the option ``-lm''.

The product of the compiling and linking is an executable file named a.out. To run the program, just type the name of that file. You can rename that file using the Unix command mv, or give it a different name from the beginning using the -o option, e.g.,

   pascal>   f90 -o inversion invert.f90

The source code of a program can be viewed, edited, and printed (using enscript), whereas the compiled file, a.out, looks like binary gibberish when you attempt to read or print it. However, it makes sense to the CPU and can be executed.


Up to main menu         Back to Types of Files         Next: Text vs. PostScript; Viewing
Bruce.Fast@Colorado.EDU