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
10#pragma once
11
24#include <stdint.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#ifdef DOXYGEN
47#define DEBUG_ASSERT_VERBOSE
48
61#define DEBUG_ASSERT_BREAKPOINT
62#else
63/* we should not include custom headers in standard headers */
64#define _likely(x) __builtin_expect((uintptr_t)(x), 1)
65#endif
66
76#ifndef __NORETURN
77#ifdef __GNUC__
78#define __NORETURN __attribute__((noreturn))
79#else /*__GNUC__*/
80#define __NORETURN
81#endif /*__GNUC__*/
82#endif /*__NORETURN*/
83
84#ifdef NDEBUG
85#define assert(ignore)((void)0)
86#elif defined(DEBUG_ASSERT_VERBOSE)
97__NORETURN void _assert_failure(const char *file, unsigned line);
135#define assert(cond) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
136#else /* DEBUG_ASSERT_VERBOSE */
137__NORETURN void _assert_panic(void);
138#define assert(cond) (_likely(cond) ? (void)0 : _assert_panic())
139#endif /* DEBUG_ASSERT_VERBOSE */
140
141#if !defined __cplusplus
142#if __STDC_VERSION__ >= 201112L
146#define static_assert(...) _Static_assert(__VA_ARGS__)
147#else
153#define static_assert(cond, ...) \
154 { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
155#endif
156#endif
157
163#ifndef DEBUG_ASSERT_NO_PANIC
164#define DEBUG_ASSERT_NO_PANIC (1)
165#endif
166
167#ifdef __cplusplus
168}
169#endif
170
__NORETURN void _assert_failure(const char *file, unsigned line)
Function to handle failed assertion.
#define __NORETURN
hidden (__) NORETURN definition
Definition assert.h:80