[previous] 3131 [next] Hard coded 'magic' number, '%s', used to define the size of a bit-field.
Constants

An integer constant has been used to define the size of a bit-field.

If the size of the bit-field is also used in other contexts it may be better to define the constant as a macro or an enum constant. Message 3131 will not be generated in these contexts and the macro or enum constant can be reused wherever needed. Giving the constant a name may also improve readability.

Notice also that message 3131 will not be generated on a bit-field defined with a width of "1".

For example:


/*PRQA S 553,2017,2213,3602,3621 ++*/

#define NBITS 3
enum {FOUR = 4};

struct ST
{
    unsigned int  a:1;            /* OK           */
    unsigned int  b:2;            /* Message 3131 */
    unsigned int  c:NBITS;        /* OK           */
    unsigned int  d:FOUR;         /* OK           */
};

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents