Need clarity on structure alignment

D

David Thompson

I remember seeing something that left me with the impression that C (C++?)
guarantees that a struct will be aligned on a pointer-size boundary (using
the std mem mgr). (?) Something about 4-byte struct alignment (on a 32-bit
machine no doubt) sticks in my mind.
Space returned by malloc (and realloc and calloc) must be correctly
(sufficiently) aligned for _any_ C datatype on a given implementation.
This is not limited to pointers, but if you happen to be using structs
whose only large components are pointers, on a machine with nontrivial
alignment requirements, you might notice it with respect to pointers.
 

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

structure alignment rules 4
Alignment problems 20
Alignment of a structure. 6
struct alignment 14
malloc and alignment question 8
gcc alignment options 19
determining alignment of objects 5
Alignment, Cast 27

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top