Thread: Access to struct members

  1. #1
    Registered User
    Join Date
    Jan 2017

    Access to struct members


    New to the forum and relatively new to the C language (mainly used for embedded 8051). Porting code from Kiel to SDCC compiler for work and struggling as my code is not compiling... (it does compile in Kiel but then again I would love to know more how it works as I have not seen this behaviour before)..

    So I've got a header file with a struct:

    typedef union
              unsigned long u32;
                       unsigned char     hh;
                       unsigned char     hl;
                      unsigned char     lh;
                       unsigned char     ll;
              } u8;
    } HighLow;

    On another header file I have a different struct:

    typedef struct
          unsigned char                 id;
          unsigned char                 ef;                           
          unsigned char                 rtr;                          
          unsigned char                 dlc;                    
          unsigned char                 buffer[MAX_PAYLOAD_SIZE];
    } FRAME;
    And in my source file I have a function that access’s both structures and assigns the value of a register to it:

    Core_Rx(FRAME* myFrame)
    Frame-> id.u8.ll = HW_get_8bit_reg(RXMESSAGE_REG);

    Is this possible? How does this work if so?


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The only way that makes any sense is if you have
    HighLow id;
    as the first member of the FRAME structure.
    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. How to access private members in class?
    By akif13 in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2014, 05:30 AM
  2. Replies: 10
    Last Post: 10-14-2011, 01:31 PM
  3. How to access members of a struct
    By Bnchs in forum C Programming
    Replies: 9
    Last Post: 03-25-2008, 02:28 PM
  4. Not able to access private data members
    By smitsky in forum C++ Programming
    Replies: 31
    Last Post: 05-09-2004, 07:06 PM
  5. Access violation on class members
    By filler_bunny in forum Windows Programming
    Replies: 2
    Last Post: 05-03-2004, 02:58 AM

Tags for this Thread