Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 INRIA
3 * Copyright (C) 2016 Freie Universität Berlin
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
22#ifndef ASSERT_H
23#define ASSERT_H
24
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifdef DOXYGEN
48#define DEBUG_ASSERT_VERBOSE
49
62#define DEBUG_ASSERT_BREAKPOINT
63#else
64/* we should not include custom headers in standard headers */
65#define _likely(x) __builtin_expect((uintptr_t)(x), 1)
66#endif
67
77#ifndef __NORETURN
78#ifdef __GNUC__
79#define __NORETURN __attribute__((noreturn))
80#else /*__GNUC__*/
81#define __NORETURN
82#endif /*__GNUC__*/
83#endif /*__NORETURN*/
84
85#ifdef NDEBUG
86#define assert(ignore)((void)0)
87#elif defined(DEBUG_ASSERT_VERBOSE)
98__NORETURN void _assert_failure(const char *file, unsigned line);
136#define assert(cond) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
137#else /* DEBUG_ASSERT_VERBOSE */
138__NORETURN void _assert_panic(void);
139#define assert(cond) (_likely(cond) ? (void)0 : _assert_panic())
140#endif /* DEBUG_ASSERT_VERBOSE */
141
142#if !defined __cplusplus
143#if __STDC_VERSION__ >= 201112L
147#define static_assert(...) _Static_assert(__VA_ARGS__)
148#else
154#define static_assert(cond, ...) \
155 { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
156#endif
157#endif
158
164#ifndef DEBUG_ASSERT_NO_PANIC
165#define DEBUG_ASSERT_NO_PANIC (1)
166#endif
167
168#ifdef __cplusplus
169}
170#endif
171
172#endif /* ASSERT_H */
__NORETURN void _assert_failure(const char *file, unsigned line)
Function to handle failed assertion.
#define __NORETURN
hidden (__) NORETURN definition
Definition assert.h:81