[previous] 1479 [next] Object of enum type is being modified with an arithmetic compound assignment operator.
Arithmetic type - Enum types REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

The value of an enum object is being modified using an arithmetic compound assignment operator (*=, /=, %=, +=, -=, <<=, >>=). This is permitted in the C language but it is dangerous because it could result in the object containing a value which is not a valid member of the enumeration.

For example:


/*PRQA S 2017,2211,2213,3120,3227,3408,3447,3448,3602,4130 ++*/

typedef enum { RED = 2, GREEN = 4, BLUE = 6 } COLOUR;

extern COLOUR col;

extern void foo(int n)
{
    col *= n;                   /* Message 1479 and 1318 */
    col /= 4;                   /* Message 1479 and 1318 */
    col += GREEN;               /* Message 1479 and 1318 */

    return;
}

See also:

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