V2544. MISRA. The values used in expressions should have appropriate essential types.
This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.
This diagnostic rule is relevant only for C.
The MISRA C standard defines its own type model, called the essential type model.
The values used in expressions should have appropriate essential types.
The C language has no restrictions on operations with basic types, but some of these operations may lead to unspecified/undefined behavior, or make no sense at all.
For example:
- obtain a value in an array using a
Boolean
type index; - try to change the sign of an unsigned integer;
- work with a bit representation using variables of non-unsigned type.
Implicit conversion to Boolean
may also be dangerous, since not all decimals may be represented in the binary number system.
void Foo(float f, _Bool other_expr)
{
if (f || other_expr) ....
}
The following table gives intersections of operands and operations types, which should not be composed in expressions. These intersections are marked with an X
.

The example:
void Foo(float f, _Bool b, int a[], enum E e)
{
if (~a[(e ? 1 : 2) >> (-b * f --> +b) << signed(-24U)]) ....;
}
Exception. Expression of a signed type with a positive value can be used as the right-hand operand of a shift operator (>>
, <<
).
void foo(signed vi, unsigned _)
{
assert(vi >= 0);
_ >> vi;
_ << vi;
}
This diagnostic is classified as:
|