Section CS251-06    01/31/2000

Quiz #1
More about recitation quizes
Notes about file formats, comments, style, etc
The C Preprocessor
Makefile  and make

  • More about recitation quizes:

  •   Usually 2 questions  about 5 mins
        Two types:
           (1) Trivial  questions about concepts/definitions...
           (2) Code Analysis ( less than 20 lines code)

     Preparation  : Read the textbook and understand the lecture notes (www.cs.unm).
     


  • Notes about file formats, comments, style, etc --

  •     PROGRAM 1 due THU 2/10/00 5PM
        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, 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
        http://www.cslab.vt.edu/manuals/gcc/cpp_toc.html
        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 longer constructs.

    The C preprocessor provides four separate facilities that you can use as you see fit:


  •  Makefile  and make

  •     http://www.cslab.vt.edu/manuals/make/make_toc.html
           Make
               General
                   -Make is useful for updating independent files.
                   -Use it to update executable c++ files compiled from multiple source and header files.
                Command Line
                    -% make
                            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

            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----
     



  • C++ class
            An example
             ----Header file----
              ...
            class foo
    {
             public:
              foo();
              ~foo();
             private:
              char*  _name;
              ...
     };
             ...
         -- End  ----