P
Peter Ammon
Here's some code under consideration:
struct s {
int i;
};
char buff[sizeof(s)];
new(buff) s;
I claim that this code is potentially dangerous because buff may not
have the alignment that struct s requires. My opponent claims that this
is not a concern, and if it were, then placement new would be mostly
useless.
He also claims that buff should be typed as an array of unsigned char,
because otherwise you risk generating a trap representation for one of
the chars. I claim that's not a problem until you use the value of one
of the chars in buff.
Who's right for each of the two above points of contention? Thanks,
-Peter
struct s {
int i;
};
char buff[sizeof(s)];
new(buff) s;
I claim that this code is potentially dangerous because buff may not
have the alignment that struct s requires. My opponent claims that this
is not a concern, and if it were, then placement new would be mostly
useless.
He also claims that buff should be typed as an array of unsigned char,
because otherwise you risk generating a trap representation for one of
the chars. I claim that's not a problem until you use the value of one
of the chars in buff.
Who's right for each of the two above points of contention? Thanks,
-Peter