Unions and Structures

Joined
Jan 29, 2010
Messages
1
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top