struct alignment

R

rassuls

Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell
 
G

Gordon Burditt

Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell

You don't get to change the alignment. Only a compiler implementor
does.

Alignment is a requirement that certain data types must be stored
at an address that is a multiple of some constant for that type,
due to hardware requirements (if you violate them, you get some
kind of exception) or optimization (aligning doubles to a multiple
of, say, 4 speeds up loading them from memory). For example, a
data type of size 4 bytes might be aligned to a multiple of 4 bytes.

Different alignment requirements sometimes mean different sizes for
the same structure on different machines, and differing amounts of
padding between elements.

Gordon L. Burditt
 
T

Tim Prince

Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell
A compiler is likely to leave unused space (padding) between structs or
between fields of differing types, to allow for access by the load and store
instructions associated with the type. There is often a pragma to override
this (packed storage), or a compiler option to set a lower ceiling on the
amount of padding. A common consequence would be inability to use wide
loads and stores, such as the 128-bit parallel instructions provided by
several common architectures. Compiling parts of a program with inconsistent
alignment options could lead to run-time failure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top