max_align_t
From cppreference.net
|
定义于头文件
<stddef.h>
|
||
|
typedef
/*由实现定义*/
max_align_t
;
|
(C11 起) | |
max_align_t
是一种类型,其对齐要求至少与所有标量类型的对齐要求同样严格(同样大)。
目录 |
注释
由分配函数(如
malloc
)返回的指针适用于任何对象,这意味着它们的对齐方式至少与
max_align_t
一样严格。
示例
运行此代码
#include <inttypes.h> #include <stdalign.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> int main(void) { size_t a = alignof(max_align_t); printf("Alignment of max_align_t is %zu (%#zx)\n", a, a); void *p = malloc(123); printf("The address obtained from malloc(123) is %#" PRIxPTR"\n", (uintptr_t)p); free(p); }
可能的输出:
Alignment of max_align_t is 16 (0x10) The address obtained from malloc(123) is 0x1fa67010
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.19 通用定义 <stddef.h> (页码: 待定)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.19 通用定义 <stddef.h> (页: 211)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.19 通用定义 <stddef.h> (页码: 288)
参见
|
C++ 文档
关于
max_align_t
|