rspec/rules/S814/rule.adoc
Arseniy Zaostrovnykh 7ca29f686f Force linebreaks
2021-02-02 15:02:10 +01:00

31 lines
1.4 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Some types are not very well suited for use in a bit-field, because their behavior is implementation-defined. When defining a bit-field, you should stick to the following safe and portable types:
* In C: ``++signed short++``, ``++unsigned short++``, ``++signed char++``, ``++unsigned char++``, ``++signed int++``, ``++unsigned int++`` or ``++_Bool++``
* In {cpp} before {cpp}14: all enumerated types, as well as ``++signed short++``, ``++unsigned short++``, ``++signed char++``, ``++unsigned char++``, ``++signed int++``, ``++unsigned int++``, ``++signed long++``, ``++unsigned long++``, ``++signed long long++``, ``++unsigned long long++````++ or bool++``
* In {cpp} starting at {cpp}14: all enumerated and integral types
== Noncompliant Code Example
----
// Assuming we are in C
int b:3; // Noncompliant - may have the range of values 0..7 or -4..3
----
== Compliant Solution
----
unsigned int b:3;
----
== See
* MISRA C:2004, 6.4 - Bit fields shall only be defined to be of type _unsigned int_ or _signed int_.
* MISRA {cpp}:2008, 9-6-2 - Bit-fields shall be either _bool_ type or an explicitly _unsigned_ or _signed_ integral type.
* MISRA C:2012, 6.1 - Bit-fields shall only be declared with an appropriate type
* https://wiki.sei.cmu.edu/confluence/x/VNYxBQ[CERT, INT12-C.] - Do not make assumptions about the type of a plain int bit-field when used in an expression