[previous] 3123 [next] Hard coded 'magic' character constant, %s.
Constants

A character constant has been used.

It may be better to define the constant as a macro, an enum constant or a "const" qualified object. Message 3123 will not be generated in these contexts and the definition can be located where it can more easily be reviewed and maintained - rather than buried within executable code. This is particularly important for maintainability if the same constant is reused in several places. Giving the constant a name may also improve readability.

This message will not be generated for the null character constant '\0' because it is so commonly used in initializations,

For example:


/*PRQA S 2017,2213,3198,3199,3203,3218,3408,3602,3625 ++*/

#define FLAG 'X'
enum {EFC = 'X'};
static const char flag = 'X';

extern void foo( void )
{
    char pc;

    pc = 'X';                   /* Message 3123 */
    pc = FLAG;                  /*              */
    pc = EFC;                   /*              */
    pc = flag;                  /*              */
}


No MISRA C:2012 Rules applicable to message 3123


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents