Practical C Programming, 3rd Edition

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

Категории