MTH 568 - Compuational Science




Course Outline


Contact Info

Source Code, Compiling, and Executable Code

C is a highly robust and flexible programming language that is very useful for scientific programs.  Before a program can be executed by a computer, it must undergo a transformation from a human-readable format to something that can be understood by the computer.  The source code is the C program that is written by a human using a text editor, such as vi.  An example of a source code in C is given here.  This code is easily written and read by humans and can be translated into a code that can be executed by a computer.  Source code is converted to executable code (which is useful to the computer) by a process called compiling.  All source code in C usually has a ".c" suffix appended to the filename, as in the case of hello_world.c file, to indicate that the source code is written in C.  The source code can be transformed into executable code by using the GNU C compiler (gcc).  The executable or machine code produced is named whatever you wish using the "-o" flag of the gcc compiler.  For convenience, the execuatable is usually named the same name as the source code (without the ".c" suffix).  The executable code can then be run on the machine by typing ./ (to tell the shell that the program is located in the current directory) followed by the name of the executable code.

  • Make sure that the gcc compiler is set up to work with your computer account.
    • Add the command use -quiet comp to your .aliases file.
    • Resource .cshrc by typing source .cshrc
    • Check to see if gcc exists by typing which gcc
  • Compile the source code.
    • gcc -o hello_world hello_world.c 
  • Run the program.
    • ./hello_world