[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
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: Preprocessor statements can be used for (but see [1,2,6-8] for C++ better type-safe alternatives):

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


last edited (November 16, 2006) by bilderbikkel, Number of views: 6489, Current Rev: 16 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.