Unions and Structures

Discussion in 'C Programming' started by jsnayak, Jan 29, 2010.

  1. jsnayak

    jsnayak

    Joined:
    Jan 29, 2010
    Messages:
    1
    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.
     
    jsnayak, Jan 29, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    9
    Views:
    433
    Jeffrey D. Smith
    Oct 16, 2003
  2. Alfonso Morra
    Replies:
    11
    Views:
    754
    Emmanuel Delahaye
    Sep 24, 2005
  3. Jason Curl

    Unions and structures implementation in C

    Jason Curl, Oct 12, 2005, in forum: C Programming
    Replies:
    4
    Views:
    824
    Default User
    Oct 12, 2005
  4. anon.asdf@gmail.com

    byte alignment in structures and unions

    anon.asdf@gmail.com, Aug 9, 2007, in forum: C Programming
    Replies:
    20
    Views:
    759
    Richard
    Aug 10, 2007
  5. Ravikiran

    Difference between Unions and Structures...

    Ravikiran, Nov 3, 2008, in forum: C Programming
    Replies:
    7
    Views:
    638
    CBFalconer
    Nov 3, 2008
Loading...

Share This Page