Quiz #1
More about recitation quizes
Notes about file formats, comments, style, etc
The C Preprocessor
Makefile and make
Preparation : Read the textbook and
understand the lecture notes (www.cs.unm).
You are not required to use any SPECIFIC set of rules for indenting, white space, comment headers, etc, BUT
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 provides four separate facilities that you can use as you see fit:
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.
-commands
-grouped below the dependency line
-a command line must begin with a tab !!
Explanation:
target: depend1 depend2
<tab> command3
depend1: source1
<tab> command1
depend2: source2
<tab> command2
Example from Assignment 1:
---Cut Here----
# Makefile for
CS251 Program 1
# WARNING! 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!
# Compile-time
flags
CFLAGS=-g -Wall
-pedantic -c
# Command for
compilation
CPP=g++
# Command for
linking
LINK=g++
# Our application
name
APP=blocks
# Our object
files
OFILES=Board.o
Block.o Main.o
# Default target
all:
$(APP)
# Linking the
main app
$(APP): $(ALLDEP)
$(OFILES)
$(LINK) $(OFILES) -o $(APP)
# Compiling the
source files
%.o:
%.C %.h $(ALLDEP)
$(CPP) -c $(CFLAGS) $*.C -o $@
# Alternate target:
cleaning
clean:
rm -f *.o core *~
#######
# Other dependencies
Main.o: Board.h
Board.o: Block.h
---Cut Here----