30.5 Preprocessor

I l @ ve RuBoard

  • Always put parentheses, ( ), around each constant expression defined by a pre-processor # define directive:

     #define BOX_SIZE (3 * 10) /* Size of the box in pixels */ 
  • Put ( ) around each argument of a parameterized macro:

     #define SQUARE(x) ((x) * (x)) 
  • Surround macros that contain complete statements with curly braces:

     // A fatal error has occurred.  Tell user and abort #define DIE(msg) {printf(msg);exit(8);} 
  • When using the #ifdef / #endif construct for conditional compilation, put the #define and #undef statements near the top of the program and comment them.

  • Whenever possible, use const instead of #define .

  • The use of inline functions is preferred over the use of parameterized macros.

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