P
puzzlecracker
Why Attempt #3 is Deplorable
First, let's consider a few reasons why Attempt #3 above truly is
deplorable form:
1. Alignment. Unlike dynamic memory acquired by :
perator new(), the
x_ character buffer isn't guaranteed to be properly aligned for
objects of type X. To make this work more reliably, the programmer
could use a "max_align" union, which is usually implemented as
something like:
union max_align {
short dummy0;
long dummy1;
double dummy2;
long double dummy3;
void* dummy4;
/*...and pointers to functions, pointers to
member functions, pointers to member data,
pointers to classes, eye of newt, ...*/
};
It would be used like this:
union {
max_align m;
char x_[sizeofx];
};
I don't understand how this will fix the alignment issue.
Thanks
First, let's consider a few reasons why Attempt #3 above truly is
deplorable form:
1. Alignment. Unlike dynamic memory acquired by :
x_ character buffer isn't guaranteed to be properly aligned for
objects of type X. To make this work more reliably, the programmer
could use a "max_align" union, which is usually implemented as
something like:
union max_align {
short dummy0;
long dummy1;
double dummy2;
long double dummy3;
void* dummy4;
/*...and pointers to functions, pointers to
member functions, pointers to member data,
pointers to classes, eye of newt, ...*/
};
It would be used like this:
union {
max_align m;
char x_[sizeofx];
};
I don't understand how this will fix the alignment issue.
Thanks