I have been using unions in this format (visual c++ 6.0)and it never gave me any problem.
struct Foo
{
int a : 10;
int b : 10;
int c : 12;
};
union
{
int buffer;
Foo data;
};
By specifying the size of each member 10 means 10 bits for that element) in the structure and ensuring that the total size specified in the structure is the size of the union size, I can consolidate data easily.
Recently, I tried to do things a little differently:
struct Foo
{
int a : 10;
int b[10] : 1;
int c : 12;
};
union
{
int buffer;
Foo data;
};
I hoped that the an array of size 10 with each member of the array having size 1 bit will be created. But I am getting compiler errors. Is this possible. If so where is my mistake.
struct Foo
{
int a : 10;
int b : 10;
int c : 12;
};
union
{
int buffer;
Foo data;
};
By specifying the size of each member 10 means 10 bits for that element) in the structure and ensuring that the total size specified in the structure is the size of the union size, I can consolidate data easily.
Recently, I tried to do things a little differently:
struct Foo
{
int a : 10;
int b[10] : 1;
int c : 12;
};
union
{
int buffer;
Foo data;
};
I hoped that the an array of size 10 with each member of the array having size 1 bit will be created. But I am getting compiler errors. Is this possible. If so where is my mistake.