Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Intermediate C++
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.
  • Learn at your own pace... anytime, anywhere!

Macros & Compilation

  • By this time you have quite a few iterations of your “Auto” program. Here we are going to split it into multiple versions all in the same file.
    • Let’s start with a “test” version versus “production” version.
    • You may have placed “cout” statements at different points in the program for debugging purposes. If you’ve taken them out, put them back. If you haven’t (you coded it right the first time? A miracle!) then now’s your chance to add copious debugging statements at key points in the code.
    • Place your debugging statements inside the following conditional compilation:
      #ifdef DEBUGGING
      { your debugging code }
    • When you want a debugging version of the code, add this at the beginning of each file:
      #define DEBUGGING
  • You might want varying levels of debugging. Mild debugging, e.g., print out the entry of each constructor and destructor, More debugging, e.g., each change in delta time, and Severe debugging, e.g., print the values of the parameters in each method.
    • You can accomplish this with code such as:
      #define NO_DEBUGGING 0
      #define MILD_DEBUGGING 5
      #define MORE_DEBUGGING 10
      // we will do "mild" debugging today
      #define DEBUGGING 5
      { your “mild” debugging code }
  • Instead of using a “#define” to set your debugging level, define it for the compiler on its command line. That way you won’t need to edit the source file to create a different version of the executable.
  • Compile your code with the “-E” option to see what it looks like after pre-processing.

Macros & Compilation

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  1. Intro
    • Overview
      • Pre-Processor Macros
      • Including Other Files
      • Basic Constant Definition
      • Typical Use
      • Using Macros in Macros
      • Conditional Compilation, Includes
      • Conditional Compilation
      • Good for Temporary Removal
      • Macro Functions
      • Macro Function Examples
      • Avoid Those Problems
      • Mixing C with C++
      • Pre-Defined Macros
      • Occasional Misuse
      • Compiling
      • Compiler Flags to Find Libraries
      • Other Useful Flags
      • Setting Flags for IDE
      • Uh, Almost
        • Intro 0:00
        • Overview 0:14
        • Pre-Processor Macros 2:57
          • Define with the 'Pound' Character
          • Macros Are Pre-Processed on a Textual Basis
        • Including Other Files 5:25
          • Use the 'Include' Macro When You Use a Pre-Compiled Library
          • Triangle Brackets
          • Quotes Indicate That the Include File May Be Found in the Same Directory as the File Being Compiled
          • Any Text File Can Be Included
        • Basic Constant Definition 8:54
          • 'Define' Macro Keyboard
          • 'MAX_ROWS replaced by '300'
          • Compiler Never Sees MAX_ROW
          • Literally Anything Can Be Defined
        • Typical Use 12:19
          • Application Constants
          • C++ Improvements
        • Using Macros in Macros 13:32
          • Macro Substitution Can Occur in Macro Substitution
          • Example
          • Text Replacement
        • Conditional Compilation, Includes 16:20
          • ifdef, ifndef, if, else, elif, and endif
          • Include Guards & Example
        • Conditional Compilation 20:21
          • Don't Print Out Debugging Info in the Production Code
          • Compiler Will Never See the Testing Code
          • Macros Can Be 'undef'ed
        • Good for Temporary Removal 23:27
          • 'Comment Out' Sections
          • Can't Use the // or /**/ Comment
          • Use 'ifdef'
        • Macro Functions 26:29
          • Macros Have a Facility for Creating Small In-Text Functions
          • Define a Macro Function
          • If You Need More Than One Line
        • Macro Function Examples 28:34
          • Return Area of a Circle
          • Return Volume of a Cylinder
          • What Can Happen Without Parentheses?
        • Avoid Those Problems 31:14
          • In C++, Use Inline Functions
          • Inline Functions Avoid All Other Problems That Historically Have Occurred With Macros
        • Mixing C with C++ 34:08
          • C Code Can Not Be Linked Directly with C++ Code
          • In C Header File Add
        • Pre-Defined Macros 37:18
          • Macros That Should Be Pre-Defined for Every Standards-Compliant Compiler
        • Occasional Misuse 38:39
          • Abusing the Facility
          • Example: Trying to 'look' Like Pascal
          • Allows Code to be Written Like This
        • Compiling 40:14
          • Typical Compilation Command Line
          • Compilation of One Unit at a Time
        • Compiler Flags to Find Libraries 42:34
          • Finding Other Include Files & Other Libraries to Link Into Your Application
          • Example: Create an Application that Uses the MySQL Database
        • Other Useful Flags 47:07
          • Small Set of Command Line is Most Common
          • '-c' Create an Object File From the Source
          • '-g' Add Internal Code That Allows a Run-Time Debugger to Hook into the Program
          • '-Dmacro' Set a Macro to be Defined
          • '-E' Stop After Pre-Processing
          • '-S' Stop After Compilation
        • Setting Flags for IDE 49:51
          • If You're Using Eclipse
          • Example
        • Uh, Almost 51:03