C Software for CS 241

Quickstart instructions: downloading headers and libraries, telling the compiler about the libraries, and example compiler commands.

Here is a version of the starter file for Assignments 9 and 10 that uses the GString, List, and Dictionary packages. (One other modification: it will read from a file instead of stdin if you supply a path to the file on the execute line.)

Here is a very simple introduction to using the gdb interactive debugger with C programs.

The program memerror.c, for use in the "debugging with gdb" introduction from "Advanced Mac OS X Programming" by Dalrymple and Hillegass. (Referred to in the C-tutorial.)

If you have trouble understanding exactly what a variable declaration in C means (quick, what's a "void *(*foo)[]"?), try asking cdecl.

GStrings (“Growable Strings”)
A data structure and associated library of routines, loosely modelled on Java's StringBuffer class, that expands-on-implicit-demand a partially-filled array of chars. In particular, it facilitates concatenating and dynamically expanding strings.

Documentation updated on 10 Oct 09: the routine name shrinkLengthOfStringToInt(...) had been mistyped.

Lists
A library of routines that support dynamic arrays (or linked lists) of pointers that expand behind the scenes as needed.

Documentation updated on 10 Oct 09: the routine name removeAndReturnPtrAtIndexFromList(...) had been mistyped and destroyIterator(...) was missing from the table of contents.

Dictionaries
A library of routines that support associative arrays (aka “tables” and “maps”). Suitable for implementing a symbol table.
DMalloc
A library of “wrappers” for the standard C dynamic memory allocation routines malloc, calloc, realloc & free, and for the string routines strcat, strlen, etc, that can often catch out-of-bounds array writes, verify the integrity of the data structures used to manage the runtime heap, and inform you of memory leaks.
(One advantage dmalloc has over valgrind is that if you run a program within gdb, you can set a breakpoint at dmalloc_error, which is the routine dmalloc always calls to report an error. Printing a backtrace then shows you the sequence of function calls that triggered detection of the error. Examining variables in those functions can often help to determine the cause of the problem.)
mergeCsource
A unix tool that concatenates multiple C source files into a single C source file, expanding user include files (#include "...") but not system include files (#include <...>). Allows you to organize the C code for a CS 241 assignment in multiple files for development/debugging, but submit a single source file (as required by marmoset).

Author: JCBeatty.
Last modified: 1 Jan 2010.