std::max_align_t

来自cppreference.com
< cpp‎ | types
 
 
 
类型支持
基本类型
定宽整数类型 (C++11)
定宽浮点类型 (C++23)
max_align_t
(C++11)
(C++17)
数值极限
C 数值极限接口
运行时类型信息
 
在标头 <cstddef> 定义
typedef /* 由实现定义 */ max_align_t;
(C++11 起)

std::max_align_t 是一个平凡的(C++26 前)可平凡复制 (TriviallyCopyable) (C++26 起)标准布局类型,它的对齐要求至少与每个标量类型一样严格(一样大)。

std::is_trivially_default_constructible_v<std::max_align_t>true

目录

[编辑] 注解

分配函数(如 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) 查询类型的对齐要求
(operator)[编辑]
获取类型的对齐要求
(类模板) [编辑]
(C++11)
检查类型是否为标量类型
(类模板) [编辑]
max_align_t 的 C 文档