CH 2 EXERCISES SOLUTIONS

1) During the pre-processing phase of the compiler, the #include and
   #define statements are placed in the code.  Any header files are
   placed physically into the code at the point of the #include statement.
   Symbolic constants (#define statements) are replaced by their values.  

   This may be verified with the -P option to the cc command.  The 
   preprocessed output is placed in the file source.i.

2) Include files contain function prototypes, symbolic constants,
   macros and type declarations.  Libraries contain function
   definitions.  

   Include (header) files are physically included into the source file by 
   the preprocessor.  The include files are compiled at the time the source 
   file is compiled. 

3) Each separately compiled function may be individually tested and debugged.
   When another person uses the function, they are also making use of the
   time spent in the development and testing of the function.

   When these individually compiled functions are placed within a library
   for reuse, they may be linked in with other separately compiled functions
   to create an executable.  The executable will link in only those function
   modules that are needed.  If all functions were compiled in one big file,
   then that whole big file would have to be linked in, creating much larger
   executables.

4) You will have to use the options: -L, -l (and perhaps -I).  

Optional

A) Step 1 - preprocess:
      cc -P joke_main.c   (creates joke_main.i)
      cc -S joke_main.i   (creates joke_main.s)
      as joke_main.s      (creates joke_main.o)
      ld joke_main.o      (creates a link error, so now try...)

      ld joke_main.o -lc  (link in the standard c library, creates a.out)

   Run a.out.  You will get an interesting error.  You must also include
   information that allows the compiler to know the location of the startup
   initialization code.  Look in man cc() to see what additional files must 
   be linked in.  On our system:

 ld joke_main.o /usr/ccs/lib/crti.o /usr/ccs/lib/crt1.o /usr/ccs/lib/crtn.o -lc

