Next: 15 Structures, Unions and Enumerations  Up: 14 Pre-processor  Previous: High Integrity CPP Rule 14.18  Contents

High Integrity CPP Rule 14.19   Do not use function macros, use inline functions instead.
(QA C++  1020)

Justification

Inline functions are as 'efficient' as function macros and have the predictable behaviour and type safety advantages of a regular function.

   
   #define MAX(a,b) ( ( a ) > ( b ) ? ( a ) : ( b ) )    // avoid
   
   template< typename T >                                // prefer
   inline const T& max( const T& a, const T& b )
   {
      return a > b ? a : b;
   }
Exclusive with

Rule 14.14

See also

Rule 14.17

Reference

Effective C++ Item 1;Industrial Strength C++ 13.5;


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP