π prelude
Useful C header files
Loading...
Searching...
No Matches
hint.h
Go to the documentation of this file.
1
/*
2
* π prelude - debug.h
3
* Copyright (c) 2026 Fawn <rubiefawn@gmail.com>
4
*
5
* Permission to use, copy, modify, and distribute this software for any
6
* purpose with or without fee is hereby granted, provided that the above
7
* copyright notice and this permission notice appear in all copies.
8
*
9
* THE SOFTWARE IS PROVIDED βAS ISβ AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
*/
17
20
#pragma once
21
34
#if defined(__cplusplus) && __cpp_lib_unreachable >= 202202L
35
#include <utility>
36
#define unreachable() std::unreachable()
37
#elif __STDC_VERSION__ < 202311L || !defined(unreachable)
38
#ifdef _MSC_VER
39
#define unreachable() __assume(0)
40
#elif defined(__GNUC__) || defined(__clang__)
41
#define unreachable() __builtin_unreachable()
42
#elif __STDC_VERSION__ >= 201112L
43
_Noreturn
static
inline
void
__c11_unreachable(
void
) {}
44
#define unreachable() __c11_unreachable()
45
#else
46
#warning No suitable compiler intrinsic found, unreachable() will have no effect
47
#define unreachable()
48
#endif
49
#endif
50
68
#ifndef NDEBUG
69
#define assume(COND)
70
#elif __cplusplus >= 202302L
71
#define assume(COND) [[assume(COND)]]
72
#elif defined(_MSC_VER)
73
#define assume(COND) __assume(COND)
74
#elif defined(__clang__)
75
#define assume(COND) __builtin_assume(COND)
76
#elif defined(__GNUC__)
77
#if __has_attribute(assume)
78
#define assume(COND) [[gnu::assume(COND)]]
79
#endif
80
#endif
81
#ifndef assume
82
#ifdef unreachable
83
#warning assume() will evaluate its condition parameter, avoid using conditions with side effects
84
#define assume(COND) do { if (COND) {} else { unreachable(); } } while (0)
85
#else
86
#warning No suitable compiler intrinsic found, assume() will have no effect
87
#define assume(COND)
88
#endif
89
#endif
hint.h
Generated by
1.16.1