MISRA C++:2008 Rule 9-6-4
Named bit-fields with signed integer type shall have a length of more than one bit
Description
Rule Definition
Named bit-fields with signed integer type shall have a length of more than one bit.
Rationale
Variables with signed integer bit-field types of length one might have values that do
not meet developer expectations. For instance, signed integer types of fixed width such as
std::int16_t
(from cstdint
) have a two's complement
representation. In this representation, a single bit is just the sign bit and the value
might be 0 or -1.
Polyspace Implementation
The checker flags declarations of named variables having signed integer bit field types of length equal to one.
Bit field types of length zero are not flagged.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Classes |
Category: Required |
Version History
Introduced in R2013b