![]() |
![]() |
1461 | ![]() |
||||
![]() | |||||||
| Enumerations | REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers | ||||||
It should rarely be necessary to convert to an enum type. In this particular case, the value of a constant expression is being converted (either implicitly or explicitly) to an enumerated type. The value concerned is not a valid member of the enumeration but happens to be a value which can be generated from the bitwise inclusive OR (|) of some of the enumeration constants. Although the C language allows this operation it is almost certainly a dangerous error and should be rectified. Message 1317 is generated in the more general case when the value of the constant expression is not a member of the enumeration. For example:
/*PRQA S 1277,2006,2017,2211,2213,3120,3198,3199,3203,3227,3408,3447,3602 ++*/
enum ET
{
RED = 0x0001,
AMBER = 0x0002,
GREEN = 0x0004
};
extern void func1(enum ET p);
extern enum ET foo(int m)
{
enum ET ena;
ena = 0x0003; /* Message 1461 and 1412 */
ena = 10; /* Message 1317 and 1412 */
ena = (enum ET)0x0003; /* Message 1461 and 1484 */
ena = (enum ET)10; /* Message 1317 and 1484 */
func1(0x0003); /* Message 1461 and 1411 */
func1(10); /* Message 1317 and 1411 */
if (m > 0)
{
return 0x0003; /* Message 1461 and 1413 */
}
else
{
return 10; /* Message 1317 and 1413 */
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |