[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppPreprocessor
Preprocessor Directives include: Preprocessor are useful for:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppPreprocessor
(C++) Preprocessor and Preprocessor Directives
Preprocessing, as the name says, is processing before something happens. In the special case of the C++ Preprocessor, it is a processing of your code before the compilation. Usually preprocessor directives are used for debugging or conditional compiling.Preprocessor Directives include: Preprocessor are useful for:
- Creating #include guards [3,9].
- Creating the assert statement [4,5,10] or other debugging tricks
References
- 1) Scott Meyers. Effective C++ (3rd edition).ISBN: 0-321-33487-6. Item 2: Prefer consts, enums and inlines to #defines
- 2) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4. Chapter 7.9.4: 'Avoid macro's'
- 3) Herb Sutter,Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 24: 'Always write internal #include guards. Never write external #include guards'.
- 4) Herb Sutter,Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 68: 'Assert liberally to document internal assumptions and invariants'.
- 5) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4. Advice 24.5.18: 'Explicitly express preconditions, postconditions, and other assertions as assertions'.
- 6) Jarrod Hollingworth, Bob Swart, Mark Cashman, Paul Gustavson. Sams C++ Builder 6 Developer's Guide. ISBN: 0-672-32480-6. Chapter 3, paragraph 'Know when to use the preprocessor', lines 1-2: 'It is not appropriate to use the preprocessor for defining constants or for creating function macro's. Instead, you should use const variables or enum types for constants and use inline function (or inline template function) to replace a function macro.
- 7) Jesse Liberty. Sams teach yourself C++ in 24 hours. ISBN: 0-672-32224-2. Hour 21, chapter 'Using #define for constants': 'This is almost never a good idea, however, because #define merely makes a string substitution and does no type checking.'
- 8) Jesse Liberty. Sams teach yourself C++ in 24 hours. ISBN: 0-672-32224-2. Hour 21, chapter 'Macros versus functions and templates': 'Macros suffer from four problems in C++. [...] The final problem, however is the biggest: macros are not type safe. [...] Templates overcome this problem.'
- 9) Jesse Liberty. Sams teach yourself C++ in 24 hours. ISBN: 0-672-32224-2. Hour 21, chapter 'Inclusion and inclusion guards': 'It never hurts to use inclusion guards. Often they will save you hours of debugging time'. Also: hour 24, chapter 'include guards': 'All header files should use inclusion guards'.
- 10) Jesse Liberty. Sams teach yourself C++ in 24 hours. ISBN: 0-672-32224-2. Hour 24, chapter 'assert()': 'Use assert freely'.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
