Section CS251-06 01/31/2000
More about recitation quizes
about file formats, comments, style, etc
The C Preprocessor
Makefile and make
about recitation quizes:
Usually 2 questions about 5 mins
questions about concepts/definitions...
Analysis ( less than 20 lines code)
Preparation : Read the textbook and
understand the lecture notes (www.cs.unm).
about file formats, comments, style, etc --
PROGRAM 1 due THU 2/10/00
You MUST include YOUR FULL
NAME and YOUR EMAIL ADDRESS at the top of EVERY FILE YOU WRITE!
You are not required to use
any SPECIFIC set of rules for indenting, white space, comment headers,
You MUST indent your code to
reflect its actual block structure! The specifics are up to
you as long as you are consistent! (emacs will do indenting for youautomatically!
Just type <TAB>!)
The C Preprocessor
The C preprocessor is a macro processor
that is used automatically by the C compiler to transform your program
before actual compilation. It is called a macro processor because it allows
you to define macros, which are brief abbreviations for
The C preprocessor provides four separate facilities that you can use
as you see fit:
Inclusion of header files. These are files of declarations that
can be substituted into your program.
Including a header file produces the same results in C compilation
as copying the header file into each source file that needs it. But such
copying would be time-consuming and error-prone. With a header file, the
related declarations appear in only one place. If they need to be changed,
they can be changed in one place, and programs that include the header
file will automatically use the new version when next recompiled.
Macro expansion. You can define macros, which are
abbreviations for arbitrary fragments of C code, and then the C preprocessor
will replace the macros with their definitions throughout the program.
Conditional compilation. Using special preprocessor commands, you
can include or exclude parts of the program according to various conditions.
Line control. If you use a program to combine or rearrange source
files into an intermediate file which is then compiled, you can use line
control to inform the compiler of where each source line originally came
-Make is useful for updating independent files.
-Use it to update executable c++ files compiled from multiple source and
The make command looks for the file makefile or Makefile as the default
location for its input
-% make -f file
The -f option is used to set a file name other thatn makefile or Makefile
-Blank lines are ignored
-Comments start with a #. A pound can be put anywhere in the makefile and
the comment extends from the #to the end of the current line.
-target: prerequesites (dependency)
The target is a file(?) that will be updated if the prerequesites have
been updated since the last make. In the case of a c++ program, the targets
are object files and the executable file. The prerequisites are source
and header files needed to build the target.
-grouped below the dependency line
-a command line must begin with a tab !!
target: depend1 depend2
Example from Assignment 1:
# Makefile for
CS251 Program 1
# WARNING! WARNING!
# DO >>NOT<<
COPY THIS FILE from your browser window USING CUT-AND-PASTE!
IF YOU DO, THIS FILE WILL NOT WORK!
# See http://www.cs.unm.edu/~ackley/cs251/projects/makefile-warnings.txt
for more information!
# Command for
# Command for
# Our application
# Our object
# Default target
# Linking the
$(LINK) $(OFILES) -o $(APP)
# Compiling the
%.C %.h $(ALLDEP)
$(CPP) -c $(CFLAGS) $*.C -o $@
# Alternate target:
rm -f *.o core *~
# Other dependencies
-- End ----