[previous] 1482 [next] Non-constant expression cast to enum type.
Arithmetic type - Enum types REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

The value of a non-constant expression is being cast to an enum type. This is permitted in the C language but it is dangerous because the value of the expression may not be 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 = (COLOUR) n;                               /* Message 1482 */

    return;
}

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