...
- The alignment of bit-fields in the storage unit . For (for example, the bit-fields may be allocated from the high end or the low end of the storage unit.)
- Whether or not bit-fields can overlap a storage unit boundary.
Consequently, it is impossible to write portable safe code that makes assumptions regarding the layout of bit-field structure members.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
struct bf {
unsigned int m1 : 8;
unsigned int m2 : 8;
unsigned int m3 : 8;
unsigned int m4 : 8;
}; /* 32 bits total */
void function() {
struct bf data;
unsigned char *ptr;
data.m1 = 0;
data.m2 = 0;
data.m3 = 0;
data.m4 = 0;
ptr = (unsigned char *)&data;
(*ptr)++; /* canCan increment data.m1 or data.m4 */
}
|
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
struct bf {
unsigned int m1 : 6;
unsigned int m2 : 4;
};
void function() {
unsigned char *ptr;
struct bf data;
data.m1 = 0;
data.m2 = 0;
ptr = (unsigned char *)&data;
ptr++;
*ptr += 1; /* whatWhat does this increment? */
}
|
...
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
|
| Can detect violations of this recommendation. Specifically, it reports violations if
| |||||||
| 94 S | Fully implemented | |||||||
| PRQA QA-C |
| 0310 | Partially implemented |
...