Re: Need clarity on structure alignment
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 05 Feb 2009 09:43:53 -0500
Keith Thompson wrote:
"Tony" <tony@xxxxxx> writes:"Keith Thompson" <kst-u@xxxxxxx> wrote in message news:lnk58g7d68.fsf@xxxxxxxxxxxxxxxxxx[...]Alignment requirements for different types vary depending on theI 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.
underlying hardware, and on what the compiler chooses to enforce.
You remember incorrectly. There's no rule in C (or C++) about the
relationship between the alignment requirements for structs and
those for pointers. You may have seen something about a specific
implementation.
The phrase "using the std mem mgr" suggests he may have
been thinking of malloc(), in which case he's sort of right:
If he uses malloc() to obtain memory for a struct, the memory
will in fact be properly aligned for storing a pointer. (Also
for storing a double, a union, a va_list, a time_t, and a
partridge in a pear tree, of course: malloc() memory is properly
aligned for *any* kind of data.)
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Need clarity on structure alignment
- From: Tony
- Re: Need clarity on structure alignment
- References:
- Re: Need clarity on structure alignment
- From: Tony
- Re: Need clarity on structure alignment
- From: Keith Thompson
- Re: Need clarity on structure alignment
- Prev by Date: Re: Can anyone please explain this to me -- thanks
- Next by Date: Re: Newbie here
- Previous by thread: Re: Need clarity on structure alignment
- Next by thread: Re: Need clarity on structure alignment
- Index(es):
Relevant Pages
|