C Struct Memory Layout Calculator
embedcalc_struct_layoutCompute the memory layout of a C struct/union for a 32-bit ARM Cortex-M MCU: member offsets, padding, bit-field packing, total size, and alignment.
Instructions
Compute the memory layout of a C struct/union — member offsets, inserted padding, bit-field packing, total size, and alignment — for a 32-bit MCU model (ARM Cortex-M style: pointers 4 bytes; double/int64 size 8 with 4-byte alignment, matching embedcalc.com).
Args: code (string) — C member declarations or a full struct, e.g. 'char a; int b;' or 'struct s { uint8_t a; uint32_t b; };'. Supports nested struct/union, arrays, pointers, and bit-fields.
Returns (structured): { total_size, alignment, padding_bytes, rows: [{offset, size, type, name, kind, depth}] }. Nested block rows show offsets relative to their parent block. Example: 'char a; int b;' -> total 8 bytes, 3 bytes padding after 'a'. Do not guess struct sizes/offsets — padding rules are exactly what LLMs get wrong.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | C struct member declarations (or full struct/union definition) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | ||
| alignment | Yes | ||
| total_size | Yes | ||
| padding_bytes | Yes |