C struct layout and padding calculator
Your packed log record is bigger than you expected and RAM is tight. Paste a C struct and get real byte offsets, inserted padding, and the saving from reordering members widest-first.
Open the calculator in EM·LINKBelow is a worked example. The working calculator runs free in EM·LINK.
Worked example
Example inputs
Example result
8 bytes are padding. Widest first it is 12 bytes, saving 8000 bytes over 1000 records.
| Member | Offset | Size | Padding after |
|---|---|---|---|
| flags | 0 | 1 | 3 |
| timestamp | 4 | 4 | 0 |
| channel | 8 | 1 | 3 |
| value | 12 | 4 | 0 |
| crc | 16 | 2 | 2 |
Reordered: timestamp, value, crc, flags, channel.
Your struct is parsed in your browser. Nothing is sent to us.
The working calculator is C Struct Layout & Padding in EM·LINK, our free browser tool. The button opens it directly.
How to read the result
Example: uint8, uint32, uint8, float, uint16 on 32-bit ARM is 20 bytes with 8 bytes of padding. Widest-first it is 12 bytes. Over 1000 log records that is 8 kB of RAM.
How this is calculated
Each member starts at the next multiple of its own alignment, and the struct size rounds up to its widest member so that arrays stay aligned.
The full derivation, step by step, is in the EM·LINK documentation.
Calculated per C ABI natural alignment rules in the Arm ABI documents (AAPCS) and the System V ABI for x86-64. These tools are an engineering aid, not a certification.
Next step
Shipping hundreds of units? Get OTA updates and remote config without building it yourself.
Common questions
Why is my struct bigger than the sum of its members?
Each member aligns to its natural size and the struct pads to its widest member.
Should I use packed structs?
Reordering usually saves the same space without unaligned-access penalties.
Which ABIs are supported?
32-bit ARM and 64-bit x86-64 or AArch64.
Related tools
- Number and bit inspector, to read a member value from a raw dump.
- Fixed-point Q format converter, to pick compact fixed-point members.
- Intel HEX and S-Record inspector, to find the records inside a flash image.