Chapter Summary

The operating system interface to C programs and a variety of software development tools render the Mac OS X system well suited to programming in C. The C libraries provide general-purpose C functions that make operating system services and other functionality available to C programmers. The standard C library libc is always accessible to C programs, and you can specify other libraries by using the l option to the gcc compiler.

You can write a C program by using a text editor, such as vim or emacs. C programs always have a function named main and often include several other functions. Preprocessor directives define symbolic constants and macros and instruct the preprocessor to include header files.


When you use gcc, it calls the C preprocessor followed by the C compiler and the assembler. The compiler creates assembly language code, which the assembler uses to create object modules. The linker combines these object modules into an executable file. You can use the Wall option to gcc to detect risky constructsones that are legal but suggest the possibility of later problems. Other options to gcc can help locate areas of your code that might not be portable.


Although using printf statements and the Wall option can help in tracking program bugs, it is a good practice to compile C programs routinely with the g option. Information that can be interpreted by gdb, a symbolic debugger, is then generated as part of the executable file. When you run a program under the control of gdb, you can specify points where gdb is to pause the program so that you can inquire about the values of variables, display the program stack, or use a wide range of commands to learn about many other aspects of the program's behavior.


The make utility uses a file named makefile (or Makefile) that documents the relationships among files. It determines which modules of a program are out-of-date and compiles files to keep all modules up-to-date. The dependency line, which specifies the exact dependency relationship between target and prerequisite files, is the key to the operation of a makefile. Following the dependency line are construction commands that can bring the target up-to-date. Implied dependencies, construction commands, and the make macro facility are available to simplify the writing of complex makefiles.


The Mac OS X system includes utilities that assist in keeping track of groups of files that undergo multiple revisions, often at the hands of multiple developers. These source code management systems include CVS (Concurrent Versions System). CVS is built on top of RCS but provides a much more extensive set of operations for managing directories of files that may be accessed and modified by many users. It is a good choice for managing large-scale projects and for maintaining software releases that are sent to and from other sites.

A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: