![]() |
![]() |
1413 | ![]() |
||||
![]() | |||||||
| Arithmetic type - Enum types | REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers | ||||||
A constant expression is being used as the return expression of a function. The function is of enum type but the return expression is not. This is permitted in the C language but is it really intended ? It could result in an enum object containing a value which is not a valid member of the enumeration. If the value of the constant expression does not coincide with one of the enumeration constants in the enum type, an additional message will be generated.
/*PRQA S 1277,2006,2017,2201,2203,3120,3198,3227,3408,3447,3448,3602 ++*/
typedef enum tree
{
fir = 0x0001,
cedar = 0x0002,
maple = 0x0004,
pine = 0x0008 } TREE;
extern void func1(TREE trp);
extern TREE tra;
extern TREE foo(int m)
{
if (m < 0)
{
func1(0x0002); /* Message 1411 */
tra = 0x0002; /* Message 1412 */
return(0x0002); /* Message 1413 */
}
else if (m > 0)
{
func1(0x00FF); /* Message 1411 and 1317 */
tra = 0x00FF; /* Message 1412 and 1317 */
return(0x00FF); /* Message 1413 and 1317 */
}
else
{
func1(0x0003); /* Message 1411 and 1461 */
tra = 0x0003; /* Message 1412 and 1461 */
return (0x0003); /* Message 1413 and 1461 */
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |