名前空間
変種
操作

max_align_t

From cppreference.com
< C‎ |
ヘッダー <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 Common definitions <stddef.h> (p: TBD)
  • C17標準 (ISO/IEC 9899:2018)
  • 7.19 共通の定義 <stddef.h> (p: 211)
  • C11標準 (ISO/IEC 9899:2011)
  • 7.19 Common definitions <stddef.h> (p: 288)

[編集] 関連項目

C++ ドキュメントmax_align_t について)
English 日本語 中文(简体) 中文(繁體)