![]() |
![]() |
3322 | ![]() |
||||
![]() | |||||||
| Arithmetic type - Operations | |||||||
The logical negation operator '!' has been used with an operand which is a constant expression with a value other than 0 or 1. The ISO:C90 language does not support an explicit Boolean type, but there are certain operators which generate a result of type int with a value of 0 or 1. The result may be described as effectively Boolean. There are also operators which act on operands which are interpreted in a Boolean sense. The value of the operands are permitted to be of any value but are implicitly compared with 0. The result of the logical negation operator '!' is effectively Boolean. Its operand can be a value of any scalar type but it is interpreted as effectively Boolean. Message 3322 is generated if the operand is a constant value other than 0 or 1. For example:
/*PRQA S 3120,3211,3408 ++ */
int true = !0; /* No message */
int false = !1; /* No message */
int falser = !2; /* Message 3322 */
MISRA-C:2004 Rules applicable to message 3322:
| Rule 12.6 (Advisory) | The operands of logical operators (&&, || and !) should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, != and ?:). |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |