#119583 - LiraNuna - Sat Feb 24, 2007 2:03 pm
I usually never get anwers for my questions, but I'll give it a try anyway.
I'm writing an engine that heavily relays on bitbacked unions such as:
However, when accessing variables inside the union, aren't "merging", and the size of the struct is 4, and not 2 as it should be.
Ofcourse, I tried this:
But it didn't work too.
The only way I can get the struct to be sized '2' is to comment out the union:
I don't want to use ugly tricks as "#define v5 v2" or similar. And I'm sure I'm misusing the union.
Any Ideas?
_________________
Private property.
Violators will be shot, survivors will be shot again.
I'm writing an engine that heavily relays on bitbacked unions such as:
Code: |
struct {
u16 v1 :9; union { struct { u8 v2 :3; bool v3 :1; bool v4 :1; }; // 5bit u8 v5 :5; }; // 5bit union u8 v6 :2; } name; // 16bit |
However, when accessing variables inside the union, aren't "merging", and the size of the struct is 4, and not 2 as it should be.
Ofcourse, I tried this:
Code: |
struct {
u16 v1 :9; union { struct { u8 v2 :3; bool v3 :1; bool v4 :1; } PACKED; // 5bit u8 v5 :5; } PACKED; // 5bit union u8 v6 :2; } PACKED name; // 16bit |
But it didn't work too.
The only way I can get the struct to be sized '2' is to comment out the union:
Code: |
struct {
u16 v1 :9; // union { // struct { u8 v2 :3; bool v3 :1; bool v4 :1; // }; // 5bit // u8 v5 :5; // }; // 5bit union u8 v6 :2; }; // 16bit |
I don't want to use ugly tricks as "#define v5 v2" or similar. And I'm sure I'm misusing the union.
Any Ideas?
_________________
Private property.
Violators will be shot, survivors will be shot again.