# static_assert

> C++ Atlas: `cppatlas.com/w/c/error/static_assert` | Source: https://en.cppreference.com/w/c/error/static_assert | Domain: Error handling | Standards: C11, C23

This convenience macro expands to the keyword _Static_assert.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <assert.h>
#define static_assert _Static_assert // (since C11) (removed in C23)
```

This convenience macro expands to the keyword `_Static_assert`.

### Example

```c
#include <assert.h>

int main(void)
{
    static_assert(2 + 2 == 4, "2+2 isn't 4");   // well-formed

    static_assert(sizeof(int) < sizeof(char),   // compile-time error
                  "this program requires that int is less than char");
}
```

### Notes

Since C23, `static_assert` is itself a keyword, which may also be a predefined macro, so `<assert.h>` no longer provides it.

### References

- C23 standard (ISO/IEC 9899:2024):

  - 7.2/3 Diagnostics \<assert.h> (p: TBD)

- C17 standard (ISO/IEC 9899:2018):

  - 7.2/3 Diagnostics \<assert.h> (p: 135)

- C11 standard (ISO/IEC 9899:2011):

  - 7.2/3 Diagnostics \<assert.h> (p: 186)

### See also

- [C++ documentation for Static Assertion](https://en.cppreference.com/w/cpp/language/static_assert)

---
Attribution: content from https://en.cppreference.com/w/c/error/static_assert (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.