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

_Static_assert

Prev: _Thread_local | Up: builtins | Next: _Noreturn
Rel: static_assert
Ref: cppreference — _Static_assert
Tags: #public #prog #c #builtins #tier/core


Availability

Built-in (Declaration (C11; static_assert in C23)) — requires no #include header.

Syntax & Overview

_Static_assert(const_expr, "message");

Fails compilation immediately if const_expr evaluates to 0 at compile time.

Notes & Pitfalls

Example

#include <stdint.h>

struct Header { uint32_t magic; uint32_t len; };
_Static_assert(sizeof(struct Header) == 8, "Header must be 8 bytes");

Linked from

Related notes