How to pass locations of bit-field items?

This is a discussion on How to pass locations of bit-field items? within the C Programming forums, part of the General Programming Boards category; Code: { struct input_data { unsigned char gp1:1; unsigned char gp2:1; unsigned char gp3:1; unsigned char gp4:1; unsigned char gp5:1; ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    5

    How to pass locations of bit-field items?

    Code:
    {
        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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10:06 PM
  2. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 06: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21