[previous] MISRA C:2012  Rule-20.4:  (Required) [next] A macro shall not be defined with the same name as a keyword

Amplification:

This rule applies to all keywords, including those that implement language extensions.

Example Code:


#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_2004( void )
{
    return 1;
}

#define auto AUTO                                     /* 3439      */
#define break BREAK                                   /* 3439      */
#define case CASE                                     /* 3439      */
#define char CHAR                                     /* 3439      */
#define const CONST                                   /* 3439      */
#define continue CONTINUE                             /* 3439      */
#define default DEFAULT                               /* 3439      */
#define do DO                                         /* 3439      */
#define double DOUBLE                                 /* 3439 5209 */
#define else ELSE                                     /* 3439      */
#define enum ENUM                                     /* 3439      */
#define extern EXTERN                                 /* 3439      */
#define float FLOAT                                   /* 3439 5209 */
#define for FOR                                       /* 3439      */
#define goto GOTO                                     /* 3439      */
#define if IF                                         /* 3439      */
#define int INT                                       /* 3439 5209 */
#define long LONG                                     /* 3439 5209 */
#define register REGISTER                             /* 3439      */
#define return RETURN                                 /* 3439      */
#define short SHORT                                   /* 3439 5209 */
#define signed SIGNED                                 /* 3439 5209 */
#define sizeof XSIZEOF                                /* 3439      */
#define static STATIC                                 /* 3439      */
#define struct STRUCT                                 /* 3439      */
#define switch SWITCH                                 /* 3439      */
#define typedef TYPEDEF                               /* 3439      */
#define union UNION                                   /* 3439      */
#define unsigned UNSIGNED                             /* 3439 5209 */
#define void VOID                                     /* 3439      */
#define volatile VOLATILE                             /* 3439      */
#define while WHILE                                   /* 3439      */

/* additional keywords required for C99 */
#define inline INLINE                                 /* 3439      */
#define _Bool BOOL                                    /* 3439      */
#define _Complex COMPLEX                              /*      0602 */
#define _Imaginary IMAGINARY                          /*      0602 */



QAC messages that encompass this guideline:

3439 Macro redefines a keyword.



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