...
Compliant Solution (Alignment)
This code compliant solution is explicit about the in which fields it modifies.
| Code Block | ||
|---|---|---|
| ||
struct bf {
unsigned m1 : 8;
unsigned m2 : 8;
unsigned m3 : 8;
unsigned m4 : 8;
}; /* 32 bits total */
void function() {
struct bf data;
data.m1 = 0;
data.m2 = 0;
data.m3 = 0;
data.m4 = 0;
data.m1++;
}
|
...
Compliant Solution (Overlap)
This compliant solution is also explicit in which fields it modifies.
| Code Block | ||
|---|---|---|
| ||
struct bf {
unsigned m1 : 6;
unsigned m2 : 4;
};
void function() {
struct bf data;
data.m1 = 0;
data.m2 = 0;
data.m2 += 1;
}
|
...