This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sizeof of struct with bit Field

please explain me why the sizeof (C51) returns 6 bytes for this struct instead of 5:

typedef struct DEKO_COMM_HEADER
{ UINT16 m_uiMsgOpcode;
UCHAR8 m_sblMsgPriority :2;
UINT16 m_sblDataLength :11;
UINT16 m_sblMsgTimeStamp :11;
}DEKO_COMM_HEADER, *PDEKO_COMM_HEADER;

UINT16 is typedef for unsigned int
UCHAR8 is typedef for unsigned char

thanks

Parents
  • mr dovalle

    you can n0t assumme how compiler alllocates fields in a structure in a structure

    it is undefineded in c standard you know is implermentation specifac!!!!

    you should use sizeof so compiler says how much space

    some compileer s use pragma as control alignemenent

    why you not write code to see asssemblery of compielr producingh???

Reply
  • mr dovalle

    you can n0t assumme how compiler alllocates fields in a structure in a structure

    it is undefineded in c standard you know is implermentation specifac!!!!

    you should use sizeof so compiler says how much space

    some compileer s use pragma as control alignemenent

    why you not write code to see asssemblery of compielr producingh???

Children