dimanche 28 mai 2017

For what values of alignment does std::align work as expected?

I want to use std::align to align a buffer of unsigned char to a specific power-of-two value.

So far the documentation that I looked at seems to say this should work, except for this giant caveat at the end of the description:

The behavior is undefined if alignment is not a fundamental or extended alignment value supported by the implementation (until C++17) power of two (since C++17).

I can't fully parse that. If I had to take a guess, the last part means "until C++17, the alignment needs to be a fundamental or extended alignment and after C++17, it just needs to be a power of two".

Is my parsing correct?

More importantly, I'm interested in the C++11 behavior: WTF is a fundamental or extended alignment and how can I determine what my implementation supports?

Finally, what happens if I pass a value of alignment that does satisfy the above - is it UB or just an implementation-defined result?

Aucun commentaire:

Enregistrer un commentaire