Reordering Identical C Struct Fields Cuts Size From 24 to 16 Bytes

cneuralnetwork · x · 2026-10-22

A developer demonstrated a classic but often-overlooked C fact: two structs with identical fields can differ in size purely due to declaration order — one takes 24 bytes, the other 16.

The cause is memory alignment: the compiler inserts padding so types land on properly aligned addresses. Ordering char→double→char forces padding after each char, while grouping the two chars together (char→char→double) needs only tail padding. Scale it up: across a million instances, simply reordering declarations saves roughly 8 MB of memory.

Original post →

More from coding & agent

coding & agent channel →