Determining maximum possible alignment in C++

前端 未结 6 759
情歌与酒
情歌与酒 2021-01-31 18:58

Is there any portable way to determine what the maximum possible alignment for any type is?

For example on x86, SSE instructions require 16-byte alignm

6条回答
  •  野性不改
    2021-01-31 19:25

    In C++11 std::max_align_t defined in header cstddef is a POD type whose alignment requirement is at least as strict (as large) as that of every scalar type.

    Using the new alignof operator it would be as simple as alignof(std::max_align_t)

提交回复
热议问题