On this page
static_assert
Prev: assert | Up: assert.h | Next: math.h
Rel: assert.h, _Static_assert
Ref: cppreference — static_assert
Tags: #public #prog #c #stdlib #assert #tier/core
Include
#include <assert.h>
Signature & Overview
static_assert(const_expr, "message");
Compile-time assertion alias for _Static_assert (keyword in C23).
Notes & Pitfalls
- Header convenience macro for
_Static_assert(C11; built-in keyword in C23): Fails compilation immediately if a constant expression is false.
Example
#include <assert.h>
#include <limits.h>
static_assert(CHAR_BIT == 8, "Expected 8-bit bytes");
Linked from
Related notes
- tuts/c/stdlib/assert/assert Linked here; links to this page; shared tags: #assert, #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert Linked here; links to this page; shared tags: #assert, #c, #prog, #stdlib
- tuts/c/builtins/_Static_assert Linked here; links to this page; shared tags: #c, #prog, #tier
- tuts/c/stdlib/math Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isspace shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/tolower shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/errno/errno shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/limits/CHAR_BIT shared tags: #c, #prog, #stdlib, #tier