![]() |
![]() |
3120 | ![]() |
||||
![]() | |||||||
| Constants | |||||||
An integer constant has been used. It may be better to define the constant as a macro, an enum constant or a "const" qualified object. Message 3120 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. Message 3120 is never generated for constants of value 0 or 1 because of their common use in initializations, Notice also that message 3120 is not generated for constants which are used to define the dimensions of an array (Message 3132) or the size of a bit-field (Message 3131). For example:
/*PRQA S 1305,2017,2211,2213,3205,3207,3211,3223,3408,3602,3604,3674 ++*/
#define FOUR 4
enum {FIVE = 5};
int ga = 2; /* Message 3120 */
const int gb = 3;
static int sa = 4; /* Message 3120 */
static const int sb = 5;
extern void foo(void)
{
int a = 0; /* */
int b = 1; /* */
int c = 2; /* Message 3120 */
int d = 3; /* Message 3120 */
int e = FOUR; /* */
int f = FIVE; /* */
const int cc = 2; /* */
const int cd = 3; /* */
const int ce = FOUR; /* */
const int cf = FIVE; /* */
int a1[] = { 1, 0, 0 }; /* */
int a2[] = { 2, 0, 0 }; /* Message 3120 */
int i;
for (i = 0; i < 4; ++i) /* Message 3120 */
{
}
for (i = 0; i < FOUR; ++i) /* */
{
}
for (i = 0; i < FIVE; ++i) /* */
{
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |