[previous] MISRA-C:2004  Rule  19.5:  (Required) [next] Macros shall not be #define'd or #undef'd within a block.
While it is legal C to place #define or #undef directives anywhere in a code file, placing them inside blocks is misleading as it implies a scope restricted to that block, which is not the case.

Normally, #define directives will be placed near the start of a file, before the first function definition. Normally, #undef directives will not be needed. (see Rule )

Example Code:


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

#define  L      5
#undef   L              /* MISRA Violation of Rule 19.6 */

extern S16 test_1905( void )
{
#define  M      10      /* MISRA Violation of Rule 19.5 */
#undef   M              /* MISRA Violation of Rule 19.5
                                          and Rule 19.6 */
   return 0;
}


QAC messages that encompass this guideline:

0842 Using #define or #undef inside a function.



(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