Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<stdalign.h> — an empty header in C23

In C23, <stdalign.h> provides no content. alignas and alignof are language keywords available without including this header.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stdalign.h>
alignas(type-name) declaration;
alignas(constant-expression) declaration;
alignof(type-name)

In C23, <stdalign.h> remains a standard header but provides no content (N3096, §7.15). Including it supplies no alignment functions, types or macros. alignas and alignof belong to the language and do not require this header.

Alignment restricts the addresses at which objects may be placed. alignas specifies an alignment requirement for a declared object or member; it cannot weaken natural alignment. alignof(type-name) returns a type's alignment requirement, not its size. The example checks the structure's alignment at compile time without assuming a particular byte count.

Examples

#include <stdalign.h>
#include <stdio.h>

struct Buffer {
    alignas(int) unsigned char data[sizeof(int)];
};

static_assert(alignof(struct Buffer) >= alignof(int),
              "Insufficient alignment");

int main(void)
{
    puts("ok");
    return 0;
}

Result

ok

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources