Chapter 12 - C Programming Tools

Quiz

1. Why is it helpful to have a history of your source code?
With a full history of every version of your source, you can go back and recreate (rebuild) any specific version of your software. This is particularly useful when you need to support (and debug and fix) older versions of your code that you may no longer be using yourself. You can also see how the software worked prior to changes which sometimes provides insights into behavior or problems in the current version.
2. Whatís the definition of a leaf node on an SCCS delta tree?
A leaf node of an SCCS delta tree is the latest version of a file in that branch. Only a leaf node can be deleted from the tree.
3. Whatís the benefit of the -q option of ar?
The -q option of ar allows you to quickly append a file to the archive without having ar spend the time searching the archive for a file that wonít be there.
4. Can the make utility use object modules stored in an archive file?
Yes, by using cc or ld commands that reference the archive file.
5. What does the term ěreusable functionî mean?
A reusable function is a function that is compiled and stored separately that can be linked with a program at compile time.
6. Why would you profile an executable file?
Profiling an executable program will tell you where time is spent in the program. If you notice that a large percentage of runtime is in a specific part of your program, you can try to optimize that part so the program will run faster.
7. Describe briefly what the strip utility does.
The strip utility strips away debugger and profiling information that is added to the executable file when compiled with debugging and profiling options. The strip command simply removes the information from the file saving you having to recompile the program without these options.

Exercises

12.1 Create a shared library with a simple function that returns an integer value. Then write a program to call the function and print its return value. After compiling and running the program, make a change to the library function, rebuild the library, and run the program again (without recompiling the main program).What happens if you rename the function in the shared library? [level: easy]
This activity illustrates the behavior of functions in shared libraries.
12.2 Compile ěreverse.cî and ěpalindrome.cî and place them into an archive called ěstring.aî.  Write a main program in ěprompt.cî that prompts the user for a string and then outputs 1 if the string is a palindrome and 0 otherwise. Create a make file that links ěprompt.oî with the reverse () and palindrome () functions stored in ěstring.aî. Use dbx to debug your code if necessary. [level: medium]
The main program will call functions from the archive file string.a.
12.3 Try a modern debugger such as the Borland C++ source-level debugger. How does it compare with dbx? [level: medium].
Depending on what access you have to other debuggers, what you find here could vary widely.

Projects

1. Write a paper that describes how you would use the utilities presented in this section to help manage a 10-person computing team. [level: medium]
Students who write good papers should consider a career in technical management!
2. Replace the original version of palindrome () stored in ěpalindromeî with a pointer-based version. Use SCCS to manage the source code changes and ar to replace the old version in ěstring.aî. [level: medium].
This isnít especially difficult but will take a significant amount of time to complete.