On Feb 26, 12:11 pm, Greg Herlihy <gre...@mac.com> wrote:
On Feb 26, 10:36 am, better_cs_...@yahoo.com wrote:
On Feb 26, 11:18 am, Gert-Jan de Vos <gert-
To force the unsigned char array to have the same alignment as
the Foo (which is my goal), I'd like to put these together in a
union. However, Foo has a non-trivial constructor, so it may not
be a member of a union. Do I have any othre options?
Allocate the char array dynamically:
char * fooArray = new char[sizeof(Foo)];
Now fooArray will be suitably aligned for a Foo type.
Greg
In addition to my prvious response a minute ago, your comment brings
up a side issue.
In my original post, I showed the Foo and the char array being
constructed off of the heap, and the response was that the
alignment I seek is not guaranteed. However, your response clearly
states that the alignment I seek *will* be guaranteed if they are
constructed on the heap. So, I'd like to reconfirm -- are alignment
issues indeed treated differently on the heap than off?
Thanks for the response!
object of that size".
still obey the rule. We don't know how!