Chp~17 - C+ PROGRAMMING Chapter 17 The Preprocessor The...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 17 The Preprocessor The Preprocessor and the Compiler Seeing the Intermediate Form Using #define Using #define for Constants Using #define for Tests The #else Precompiler Command Listing 17.1. Using #define. Inclusion and Inclusion Guards Defining on the Command Line Undefining Listing 17.2. Using #undef . Conditional Compilation Macro Functions Why All the Parentheses? Listing 17.3. Using parentheses in macros . Macros Versus Functions and Templates Inline Functions Listing 17.4. Using inline rather than a macro. String Manipulation Stringizing Concatenation Predefined Macros assert() Listing 17.5. A simple assert() macro . Debugging with assert() assert() Versus Exceptions Side Effects Class Invariants Listing 17.6. Using Invariants(). Printing Interim Values Listing 17.7. Printing values in DEBUG mode . Debugging Levels Listing 17.8. Levels of debugging . Summary Quiz Exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 17 The Preprocessor Most of what you write in your source code files is C++. These are interpreted by the compiler and turned into your program. Before the compiler runs, however, the preprocessor runs, and this provides an opportunity for conditional compilation. ToChapter you will learn What conditional compilation is and how to manage it. How to write macros using the preprocessor. How to use the preprocessor in finding bugs. The Preprocessor and the Compiler Every time you run your compiler, your preprocessor runs first. The preprocessor looks for preprocessor instructions, each of which begins with a pound symbol ( # ). The effect of each of these instructions is a change to the text of the source code. The result is a new source code file, a temporary file that you normally don't see, but that you can instruct the compiler to save so that you can examine it if you want to. The compiler does not read your original source code file; it reads the output of the preprocessor and compiles that file. You've seen the effect of this already with the #include directive. This instructs the preprocessor to find the file whose name follows the #include directive, and to write it into the intermediate file at that location. It is as if you had typed that entire file right into your source code, and by the time the compiler sees the source code, the included file is there. Seeing the Intermediate Form Just about every compiler has a switch that you can set either in the integrated development environment (IDE) or at the command line, and that instructs the compiler to save the intermediate file. Check your compiler manual for the right switches to set for your compiler, if you'd like to examine this file. Using #define
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 29

Chp~17 - C+ PROGRAMMING Chapter 17 The Preprocessor The...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online