J
James Dow Allen
I've hardly ever used bitfields, but now have an
application where a union of different bitfielded
structures seems like the proper solution.
For example,
union {
struct {
unsigned long f1:9, f2:4, f3:5, f4:14;
} ua;
struct {
unsigned long f12:13, f3:5, f4:14;
} ub;
} uu;
(Let's be clear: portability is *NOT* my primary goal;
if/when portability is desired, 'make' would need to
run some endianness tests and generate appropriate
definitions for the usage of f12.)
Do other c.l.c'ers ever do something like the above?
Frankly, the bitfields have such annoyances (especially
endianness dependence) that I may end up "rolling my
own" bitfields, even though C's bitfields would enhance
readability and, perhaps, time efficiency.
I used a provocative Subject line to get attention!
On my Intel-linux-gcc laptop, sizeof(uu) is 4, but
if I replace the "long"s with "short"s then
sizeof(uu) is 6. I *do* understand why this is
(I think!) but still found it amusing enough to report.
James Dow Allen
application where a union of different bitfielded
structures seems like the proper solution.
For example,
union {
struct {
unsigned long f1:9, f2:4, f3:5, f4:14;
} ua;
struct {
unsigned long f12:13, f3:5, f4:14;
} ub;
} uu;
(Let's be clear: portability is *NOT* my primary goal;
if/when portability is desired, 'make' would need to
run some endianness tests and generate appropriate
definitions for the usage of f12.)
Do other c.l.c'ers ever do something like the above?
Frankly, the bitfields have such annoyances (especially
endianness dependence) that I may end up "rolling my
own" bitfields, even though C's bitfields would enhance
readability and, perhaps, time efficiency.
I used a provocative Subject line to get attention!
On my Intel-linux-gcc laptop, sizeof(uu) is 4, but
if I replace the "long"s with "short"s then
sizeof(uu) is 6. I *do* understand why this is
(I think!) but still found it amusing enough to report.
James Dow Allen