On this page
  1. _Alignof
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

_Alignof

Prev: sizeof | Up: builtins | Next: _Generic
Rel: Arena Allocator Pattern, Memory Layout & ABI
Ref: cppreference — _Alignof
Tags: #public #prog #c #builtins #tier/standard


Availability

Built-in (Operator (C11; alignof in C23)) — requires no #include header.

Syntax & Overview

_Alignof(type)

Returns the alignment requirement in bytes of a type as size_t.

Notes & Pitfalls

Example

#include <assert.h>
#include <stddef.h>

int main(void) {
    size_t a = _Alignof(double);
    assert(a >= 1 && (a & (a - 1)) == 0); // always a power of two
}

Linked from

Related notes