Structure Padding and Packing

suggest change

Introduction

C implementations lay out structures so that each member meets its alignment requirement. An unaligned access can be slow, and on some machines, including the DEC Alpha and some ARM CPUs, it can trap.

A structure may occupy more memory than the sum of its members. The implementation may insert unnamed padding between members or after the last member, but not before the first.

Packing, which removes or reduces that padding, is an implementation extension. It is not part of ISO C. A packed structure can require unaligned member accesses, so it is not a portable way to describe a file or network layout.

Remarks

Eric Raymond has an article on The Lost Art of C Structure Packing which is useful reading.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents