std::max_align_t

< cpp‎ | types
在标头 <cstddef> 定义
typedef /* 由实现定义 */ max_align_t;
(C++11 起)

std::max_align_t 是一个平凡的标准布局类型,其对齐要求至少与每个标量类型一样严格(一样大)。

注解

分配函数(如 std::malloc)所返回的指针,适于为任何对象对齐,这表示其对齐至少与 std::max_align_t 一样严格。

示例

#include <cstddef>
#include <iostream>
 
int main()
{
    std::cout << alignof(std::max_align_t) << '\n';
}

可能的输出:

16

引用

  • C++23 标准(ISO/IEC 14882:2024):
  • 17.2.4 Sizes, alignments, and offsets [support.types.layout](第 504-505 页)
  • C++20 标准(ISO/IEC 14882:2020):
  • 17.2.4 Sizes, alignments, and offsets [support.types.layout](第 507-508 页)
  • C++17 标准(ISO/IEC 14882:2017):
  • 21.2.4 Sizes, alignments, and offsets [support.types.layout](第 479 页)
  • C++14 标准(ISO/IEC 14882:2014):
  • 18.2 Types [support.types](第 443-444 页)
  • C++11 标准(ISO/IEC 14882:2011):
  • 18.2 Types [support.types](第 454-455 页)

参阅

alignof 运算符(C++11) 查询类型的对齐要求
(C++11)
获取类型的对齐要求
(类模板)
(C++11)
检查类型是否为标量类型
(类模板)