![]() |
![]() |
1477 | ![]() |
||||
![]() | |||||||
| Enumerations | REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers | ||||||
Controlling expressions appear in if, for, while or do ... while constructs and as the first operand of a conditional operator. They are expressions which always undergo an implicit test against the value '0'. However they are most readable when formed from an operator which explicitly yields a result of 0 or 1. Message 1477 is generated when a controlling expression consists solely of an enum variable. Rather than using the variable directly, it may be preferable to code an explicit comparison with the enum constant which represents the value 0. If no such constant exists in the enumeration, there is a more fundamental problem which will be reported with message 1478. For example:
/*PRQA S 1-9999 ++*/
/*PRQA S 1477, 1478, 3344 --*/
typedef enum {FALSE, TRUE} BOOL;
typedef enum { RED = 1, BLUE = 2, GREEN = 3 } COLOUR;
extern void paint(COLOUR wall, BOOL eb)
{
if (eb) { } /* Message 1477 + 3344 */
if (eb != FALSE) { } /* */
if (wall) { } /* Message 1478 + 3344 */
if (wall != RED) { } /* */
}
No MISRA C:2012 Rules applicable to message 1477
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |