Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Unions and Structures

Reply
Thread Tools

Unions and Structures

 
 
jsnayak jsnayak is offline
Junior Member
Join Date: Jan 2010
Posts: 1
 
      01-29-2010
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Unions and Structures... Ravikiran C Programming 7 11-03-2008 10:48 PM
byte alignment in structures and unions anon.asdf@gmail.com C Programming 20 08-10-2007 04:13 PM
Unions and structures implementation in C Jason Curl C Programming 4 10-12-2005 04:35 PM
structures, structures and more structures (questions about nestedstructures) Alfonso Morra C Programming 11 09-24-2005 07:42 PM
coding conventions: pointers, structures, and unions Neil Zanella C Programming 9 10-16-2003 02:47 AM



Advertisments