Stack alignment vs. struct alignment

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm compiling for Win32 and am using the default struct alignment, which I believe is 8 bytes. I have the following structure:

struct TData
{
double value;
bool isNull;
};

I'm expecting that to be aligned to 8 bytes, and sure enough the __alignof() operator returns 8 for this structure. However, when this object gets created on the stack, it's not 8-byte aligned (the address has a remainder of 4). How do I force objects on the stack to obey the compiler alignment setting? The alignment is a critical part of some legacy code that I'm trying to migrate and I can't use byte alignment. Any help would be appreciated.

--

.



Relevant Pages

  • Re: A malloc question
    ... reliably store 100 chars followed by a struct in this memory, ... the alignment of p+100 may not be suitable for the struct. ... the paddings for memory alignment are ... malloc() will see a request of 24 byte allocation. ...
    (comp.lang.c)
  • Re: Structure size directives
    ... alignment requirements, it's a terrible idea to use e.g. ... "If you use #pragma pack to align struct or union members on ... System programmers who are concerned about code bloat et al can just ...
    (comp.lang.c)
  • Re: realloc() implicit free() ?
    ... block size as a request for one byte, and let the alignment mechanisms raise it as they will. ... is therefore suitably aligned for any type (`struct s' in particular), the value can be assigned to any type of pointer, and can then be used to access an object of that type. ... of the Standard can distort its meaning. ...
    (comp.lang.c)
  • Re: "free space" with declared type (alignment discussion)
    ... >>a function pointer member, a struct pointer member, and maybe a few ... > It doesn't put any extra constraint on alignment beyond this. ... > To assess actual alignment constraints, a structure might be used to figure how ...
    (comp.lang.c)
  • Re: Question about setjmp on Itanium HPUX.
    ... that was the sound of the alignment of your struct ... jmp_buf and your struct. ... The one value which you are guaranteed is safe for struct mystruct is ... Note that in this case, as in your original code, you need to remember ...
    (comp.lang.c)