[previous] MISRA-C:2004  Rule  19.7:  (Advisory) [next] A function should be used in preference to a function-like macro.
While macros can provide a speed advantage over functions, functions provide a safer and more robust mechanism. This is particularly true with respect to the type checking of parameters, and the problem of function-like macros potentially evaluating parameters multiple times.

Example Code:


#include "misra.h"
#include "m2cmex.h"

#define  MAX( A, B )   ( ( ( A ) > ( B ) ) ? ( A ) : ( B ) )    /* MISRA Violation */
#define  MMAX          ( 14 + 32 )
#define  HELLO         10

extern S16 test_1907( void )
{
   return 1;
}


QAC messages that encompass this guideline:

3453 A function could probably be used instead of this function-like macro.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents