![]() |
![]() |
3425 | ![]() |
||||
![]() | |||||||
| Redundancy | |||||||
Message 3425 is generated when the value resulting from a conditional operator is not used and only one branch generates side effects. This means that the 2nd or 3rd operand is a redundant expression with no side-effects. If this is really the intention, it might be better to use an 'if' statement instead. Some coding standards do not permit the 2nd and 3rd operands of a conditional operator to generate side effects at all. Message 3446 is used to identify this requirement, For example:
/*PRQA S 2017,3198,3199,3203,3205,3227,3396,3408,3440 ++*/
extern void foo(int a, int b)
{
int r;
/* Side effects in 2nd and 3rd
operands of a conditional
operator */
r = (a > 0) ? b-- : b++; /* Message 3446 */
/* Side effects in the 1st operand
of a condition operator */
r = (a++ > 0) ? a : b; /* Message 3416 */
/* This statement does nothing */
(a > 0) ? a : b; /* Message 3112 */
/* The second operand of the
conditional operator in the
following statement
is redundant */
(a > 0) ? b : b++; /* Message 3446 and 3425 */
}
MISRA C:2012 Rules applicable to message 3425:
| Rule-2.2 (Required) | There shall be no dead code |
![]() | ||
| 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 |