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
46#define DEBUG_ASSERT_VERBOSE
47
60#define DEBUG_ASSERT_BREAKPOINT
61#else
62/* we should not include custom headers in standard headers */
63#define _likely(x) __builtin_expect((uintptr_t)(x), 1)
64#endif
65
75#ifndef __NORETURN
76#ifdef __GNUC__
77#define __NORETURN __attribute__((noreturn))
78#else /*__GNUC__*/
79#define __NORETURN
80#endif /*__GNUC__*/
81#endif /*__NORETURN*/
82
83#ifdef NDEBUG
84#define assert(ignore)((void)0)
85#elif defined(DEBUG_ASSERT_VERBOSE)
96__NORETURN void _assert_failure(const char *file, unsigned line);
137#define assert(cond) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
138#else /* DEBUG_ASSERT_VERBOSE */
139__NORETURN void _assert_panic(void);
140#define assert(cond) (_likely(cond) ? (void)0 : _assert_panic())
141#endif /* DEBUG_ASSERT_VERBOSE */
142
143#if !defined __cplusplus
144#if __STDC_VERSION__ >= 201112L
148#define static_assert(...) _Static_assert(__VA_ARGS__)
149#else
155#define static_assert(cond, ...) \
156 { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
157#endif
158#endif
159
160#ifdef __cplusplus
161}
162#endif
163
164#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:79