How to pack structs?

I'm using the Keil uVision3. How do I pack structs?

Do I use __packed or is there a pragma?

is this correct? it doesn't compile...

typedef struct
{ UINT8 key_diff; UINT8 key_state;
} __packed SCmd_KeyPress;

Parents
  • How do I pack structs?

    This merits two answers. A generic one, and one specific to C51.

    Generic: You quite probably shouldn't. It's far less often a good idea than many people seem to think. The compiler usually has good reasons why it pads structs --- are you really sure you know better than your tool vendor?

    C51: You don't. There's no padding to be removed. Which begs the question: why are you even asking about it?

Reply
  • How do I pack structs?

    This merits two answers. A generic one, and one specific to C51.

    Generic: You quite probably shouldn't. It's far less often a good idea than many people seem to think. The compiler usually has good reasons why it pads structs --- are you really sure you know better than your tool vendor?

    C51: You don't. There's no padding to be removed. Which begs the question: why are you even asking about it?

Children
More questions in this forum