![]() |
![]() |
1484 | ![]() |
||||
![]() | |||||||
| 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 rather an odd thing to do. Is it intended ? If the value of the expression is a valid constant within the enumeration type, it would be better practice to use the symbolic constant instead. If the value is not valid, it may still be stored in the enum object but this would be a serious abuse of the enum type and a further message will be generated, either 1461 or 1317. For example:
/*PRQA S 2017,2211,2213,3120,3198,3227,3408,3447,3448,3602,4130 ++*/
typedef enum { RED = 1, GREEN = 2, BLUE = 4 } COLOUR;
extern COLOUR col;
extern void foo(void)
{
col = (COLOUR)2; /* Message 1484 */
col = (COLOUR)5; /* Message 1484 + 1461 */
col = (COLOUR)10; /* Message 1484 + 1317 */
return;
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |