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

Packed structure is not packed

I would like to have a packed structure (because I'm gonna store those data in flash, and need it as small as possible).

I'm using Keil 5.22 on nRF51822.

typedef struct
{
  uint16_t packedValue;
} Event;

This gives me a size of 4, which I expect.

But I can't get this struct to have a size of 2... even with

typedef __packed __attribute__((packed)) __attribute__((aligned(1))) struct
  uint16_t packedValue;
} Event;

or

#pragma pack(push)
#pragma pack(1)

typedef struct
{
  uint16_t packedValue;
} Event;

#pragma pack(pop)

What am I doing wrong?!