![]() |
![]() |
3132 | ![]() |
||||
![]() | |||||||
| Constants | |||||||
An integer constant has been used to define the size of an array. If the size of the array is also used in other contexts it may be better to define a macro or an enum constant in an appropriate location. This will improve maintainability by avoiding duplication. Giving the constant a name may also improve readability. Message 3132 will not be generated and the macro or enum constant can be reused wherever needed. Message 3132 is not generated on an array dimensioned to "1". For example:
/*PRQA S 2017,2211,2213,3203,3205,3408,3602 ++*/
#define NEL 4
enum {FOUR = 4};
extern void foo(void)
{
int a[1]; /* */
int b[4]; /* Message 3132 */
int c[NEL]; /* */
int d[FOUR]; /* */
int i;
for (i = 0; i < 4; ++i) { b[i] = 0; } /* Message 3120 */
for (i = 0; i < NEL; ++i) { c[i] = 0; } /* */
for (i = 0; i < FOUR; ++i) { d[i] = 0; } /* */
}
No MISRA C:2012 Rules applicable to message 3132
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 |