Thread: How to pass locations of bit-field items?

  1. #1
    Registered User
    Join Date
    Aug 2008

    How to pass locations of bit-field items?

        struct input_data
        unsigned char gp1:1;
        unsigned char gp2:1;
        unsigned char gp3:1;
        unsigned char gp4:1;
        unsigned char gp5:1;
        unsigned char gp6:1;
        unsigned char gp7:1;
        unsigned char gp8:1;
        } in;
        struct eight_bit_words
        unsigned char A:8;
        unsigned char B:8;
        } eight_bit;
    } un;
    I want to access the data in a variable such as un.eight_bit.A
    from an external function, without passing the entire union. Apparently I can't get an address for an object in a union, so how do I do it?

    Thanks in advance for your help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You can't take the address of a bit-field member of a struct/union.

    Yet another of the restrictions on using them.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary numbers
    By watshamacalit in forum C Programming
    Replies: 4
    Last Post: 01-14-2003, 11:06 PM
  2. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 07:24 AM
  3. Bit field confusion.
    By crag2804 in forum C Programming
    Replies: 8
    Last Post: 10-12-2002, 06:41 PM
  4. BIT field confusing
    By C-Dumbie in forum C Programming
    Replies: 4
    Last Post: 09-14-2002, 02:33 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

Tags for this Thread