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

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
  • "If you have a mixed structure, say one with a generic pointer and a memory typed pointer in the Keil compiler, and attempt to access it with an overlay of another structure, you will find that you have alignment problems"

    That has nothing whatsoever to do with alignment or packing - they are just two differently-sized data types!

    "extra padding byte (memory address type)"

    It is not a padding byte - it is a "functional" byte that carries additional information.

    "compiler put in behind the scenes for a generic pointer."

    It's not "behind the scenes" - it is a fully documented, essential part of a Keil C51 Generic Pointer!

Reply
  • "If you have a mixed structure, say one with a generic pointer and a memory typed pointer in the Keil compiler, and attempt to access it with an overlay of another structure, you will find that you have alignment problems"

    That has nothing whatsoever to do with alignment or packing - they are just two differently-sized data types!

    "extra padding byte (memory address type)"

    It is not a padding byte - it is a "functional" byte that carries additional information.

    "compiler put in behind the scenes for a generic pointer."

    It's not "behind the scenes" - it is a fully documented, essential part of a Keil C51 Generic Pointer!

Children
No data