10.6 Summary

I l @ ve RuBoard

The C++ preprocessor is a very useful part of the C++ language. It has a completely different look and feel from C++. However, it must be treated apart from the main C++ compiler.

Problems in macro definitions often do not show up where the macro is defined, but result in errors much further down in the program. By following a few simple rules, you can decrease the chances of having problems:

  • Put parentheses around everything. In particular they should enclose #define constants and macro parameters.

  • When defining a macro with more than one statement, enclose the code in { }.

  • The preprocessor is not C++. Don't use = or ;.

     #define X = 5 // Illegal #define X 5;  // Illegal #define X = 5; // Very illegal #define X 5   // Correct 

Finally, if you got this far, be glad that the worst is over.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net