rspec/rules/S5494/cfamily/rule.adoc

39 lines
999 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Bit fields allow the developers to declare a class member with a specific size.
However, the size of a bit field is also constrained by its type: even if the specified size is greater than the size of the type, the value of the bit field will not exceed the maximum value of this type. The extra bits will just create unused padding.
The incompatibility of the size of the type with the specified size can have two causes: either the specified size is a typo error (that is the most probable cause) or the developer did not realize the size of the type he chose was too small.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
class A {
unsigned int b : 55; // Noncompliant, specified size is greater than the size of unsigned int
};
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
class A {
unsigned int b : 32;
};
----
Or
----
class A {
unsigned long long int b : 55;
};
----
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]