Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 INRIA
3 * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
20
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#ifdef DOXYGEN
44# define DEBUG_ASSERT_VERBOSE
45
58# define DEBUG_ASSERT_BREAKPOINT
59#else
60/* we should not include custom headers in standard headers */
61# define _likely(x) __builtin_expect((uintptr_t)(x), 1)
62#endif
63
64#ifndef __NORETURN
65# if defined(__GNUC__) || defined(DOXYGEN)
73# define __NORETURN __attribute__((noreturn))
74# else
75# define __NORETURN
76# endif
77#endif
78
90
101__NORETURN void _assert_failure(const char *file, unsigned line);
102
103#ifdef NDEBUG
104# define assert(ignore)((void)0)
105#elif defined(DEBUG_ASSERT_VERBOSE)
143# define assert(cond) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
144#else /* DEBUG_ASSERT_VERBOSE */
145# define assert(cond) (_likely(cond) ? (void)0 : _assert_panic())
146#endif /* DEBUG_ASSERT_VERBOSE */
147
148#if !defined __cplusplus
149# if __STDC_VERSION__ >= 201112L
153# define static_assert(...) _Static_assert(__VA_ARGS__)
154# else
160# define static_assert(cond, ...) \
161 { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
162# endif
163#endif
164
170#ifndef DEBUG_ASSERT_NO_PANIC
171# define DEBUG_ASSERT_NO_PANIC (1)
172#endif
173
174#ifdef __cplusplus
175}
176#endif
177
__NORETURN void _assert_failure(const char *file, unsigned line)
Function to handle failed assertion.
__NORETURN void _assert_panic(void)
Internal function to trigger a panic with a failed assertion as identifying cause.
#define __NORETURN
Same as NORETURN.
Definition assert.h:73