名前空間
変種
操作

max_align_t

提供: cppreference.com
< c‎ | types
ヘッダ <stddef.h> で定義
typedef /*implementation-defined*/ max_align_t;
(C11以上)

std::max_align_t は、少なくともすべてのスカラー型と同じくらい厳しい (大きい) アライメント要件を持つ型です。

[編集] ノート

malloc などの確保関数によって返されるポインタはあらゆるオブジェクトに適したアライメントが行われます。 これは少なくとも max_align_t と同じくらい厳しくアライメントされるという意味です。

max_align_t は通常、最も大きなスカラー型の同義語です。 これは多くのプラットフォームでは long double であり、そのアライメント要件は8か16のいずれかです。

[編集]

#include <stdio.h>
#include <stddef.h>
#include <stdalign.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.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

[編集] 関連項目

max_align_tC++リファレンス