====================================== Notes for Lecture 2 - January 17, 2008 ====================================== * C programming model ** Source file .c Contains the C programs that you will write ** Object file .o Contains machine instructions to carry out the tasks specified in the source file. Also contains tables of symbols defined in this program that may be needed by other programs, and tables of symbols that this program needs from other programs. ** Library A library file is a collection of .o files. It is used along with the specified .o files during the linking process (see below). ** Executable command file Contains a ready-to-run program that includes all of the necessary modules and libraries. * Build process ** gcc -c compiles a source file to produce an object file ** gcc links together many object files to produce an executable * Header files ** A header file contains C code just like a source file. ** Header files are used to store information about how to use a module. ** Header files are #included by gcc -c when compiling source files. A statement #include "foo.h" in a C program causes the compiler to process all of the lines in foo.h just as if they had been copied into the source file before compilation. * Comparison between header files and library files ** Both header and library files contain information about modules. ** The header file contains information about how the module can be used. ** The library file contains the code that implements the module. ** The header file is used during compilation of clients of the module. ** The library file is used during linking. * Programming tools ** gcc - used to compile and link a program ** make - automates the build process ** shell (bash, tcsh, etc) - runs an executable command file ** emacs - text editor useful for preparing source files ** submit - used to submit completed homework assignments ** gdb - debugger program useful for some debugging tasks ** rcs (revision control system) - keeps multiple versions of file *** Keeps history of changes *** Allows retrieval of older versions *** Gives some protection against mixing up versions *** Gives some protection against accidently deleting one's work ** ssh - allows login to Zoo node from remote machine ** VNC - gives virtual Zoo desktop to a remote machine ** eclipse - an IDE (integrated development environment) for C *** Automates some of the process of code development *** Provides assistance in navigating among one's programs *** Provides syntax checking *** Provides for global program modifications * Debugging techniques ** Staring at code often doesn't work Won't find bugs where the problem is a misunderstanding between human and machine about what the code actually means. *** Example: Missing end comment pair */ Causes following text to be treated as a comment and ignored. Difficult to spot. *** Example: Forgetting to recompile after change to source code. *** Example: Editing a different copy of code than the one being tested. *** Example: Incorrect assumption about the values in variables ** Must check understanding at many levels *** Most easily done with debugging printouts. *** Debuggers are of limited usefulness **** They sometimes affect the operation of the program they're debugging **** They don't lend themselves to a careful test plan. **** The debugging statements are ephemeral and difficult to keep track of. *** Debuggers are quite useful in tracking down the source of a program crash