Do I really have to worry about alignment when using placement new operator?

后端 未结 5 1711
南笙
南笙 2020-12-05 00:43

I read this When should I worry about alignment? but I am still do not know if I have to worry about not aligned pointer returned by placement new operator - like in this e

5条回答
  •  温柔的废话
    2020-12-05 01:20

    Just because everything appears to work doesn't mean it actually does.

    C++ is a specification that defines what is required to work. The compiler can also make not required things work. That's what "undefined behavior" means: anything can happen, so your code isn't portable anymore.

    C++ does not require this to work. So if you take your code to a compiler where this doesn't work, you can't blame C++ anymore; it's your fault for misusing the language.

提交回复
热议问题