rspec/rules/S1010/cfamily/rule.adoc

45 lines
824 B
Plaintext
Raw Normal View History

== Why is this an issue?
The values which may be represented by a bit-field of length one may not meet developer expectations. Anonymous signed bit-fields of any length are allowed.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,cpp]
----
struct S
{
signed int a : 1; // Noncompliant, signed fields require at least two bits
signed int : 1; // Compliant, cannot be referenced
signed int : 0; // Compliant, cannot be referenced
};
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,cpp]
----
struct S
{
signed int a : 2; // Compliant
signed int : 1; // Compliant, cannot be referenced
signed int : 0; // Compliant, cannot be referenced
};
----
== Resources
* MISRA {cpp}:2008, 9-6-4
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S2216
endif::env-github,rspecator-view[]