rspec/rules/S2216/cfamily/rule.adoc

52 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
The values that can be represented by a signed bit field with a length of one bit may not meet developer expectations. For example according to the C99 Standard, Section 6.2.6.2, a single-bit signed bit-field has a single (one) sign bit and no (zero) value bits.
This rule does not apply to unnamed bit fields, as their values cannot be accessed.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
signed int f:1; // Noncompliant; there's only room here for the sign
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
unsigned int f:1;
----
or
----
signed int:1; // unnamed
----
or
----
signed int f:2;
----
2021-04-28 16:49:39 +02:00
== See
* MISRA C:2004, 6.5 - Bit fields of type signed int shall be at least 2 bits long
* MISRA C:2012, 6.2 - Single-bit named bit fields shall not be of a signed type
* MISRA {cpp}:2008, 9-6-4 - Named bit-fields with signed integer type shall have a length of more than one bit
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]