TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  PRE#004Checked automatically with code checker

Synopsis:Do not use the preprocessor directive #define to obtain more efficient code; instead, use inline or template methods/functions
Language:C++
Severity Level:9
Category:Preprocessor


Description:

An advantage of inline or template methods/functions is that they don't have side-effects as macros have (see [PRE#003]). Another advantage is that inline or template methods/functions are type-safe.

A macro "function" can be defined as a template function, as in:

#define MAX(p1, p2) (((p1) > (p2)) ? (p1) : (p2))

template<class T> T&
Max(
    const T& p1,
    const T& p2);


Literature References:
Ellemtel Rule 35, adapted.