I want to know the alignment guarantees of a statically allocated array of char
. Looking at other SO questions, I found some concerning dynamically allocated arrays of char
.
For statically allocated char
arrays, are they aligned such that I can placement new any type into it (provided it is sufficiently large)? Or does this only apply for dynamically allocated ones?
char buff[sizeof(T)];
T * pT = (T*) buff;
new(pT) T(); // well defined?
...
pT->~T();
If not, how can I overcome this problem?
See Question&Answers more detail:os