Bitcoin Core
31.99.0
P2P Digital Currency
src
minisketch
src
util.h
Go to the documentation of this file.
1
/**********************************************************************
2
* Copyright (c) 2018 Pieter Wuille, Greg Maxwell, Gleb Naumenko *
3
* Distributed under the MIT software license, see the accompanying *
4
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.*
5
**********************************************************************/
6
7
#ifndef _MINISKETCH_UTIL_H_
8
#define _MINISKETCH_UTIL_H_
9
10
#ifdef MINISKETCH_VERIFY
11
#include <stdio.h>
12
#endif
13
14
#if !defined(__GNUC_PREREQ)
15
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
16
# define __GNUC_PREREQ(_maj,_min) \
17
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
18
# else
19
# define __GNUC_PREREQ(_maj,_min) 0
20
# endif
21
#endif
22
23
#if __GNUC_PREREQ(3, 0)
24
#define EXPECT(x,c) __builtin_expect((x),(c))
25
#else
26
#define EXPECT(x,c) (x)
27
#endif
28
29
#if defined(__has_cpp_attribute)
30
# if __has_cpp_attribute(maybe_unused)
31
# define MAYBE_UNUSED [[maybe_unused]]
32
# endif
33
#endif
34
35
#ifndef MAYBE_UNUSED
36
# if defined(__GNUC__)
37
# define MAYBE_UNUSED __attribute__((unused))
38
# else
39
# define MAYBE_UNUSED
40
# endif
41
#endif
42
43
/* Assertion macros */
44
49
#define CHECK(cond) do { \
50
if (EXPECT(!(cond), 0)) { \
51
fprintf(stderr, "%s:%d: %s\n"
, __FILE__, __LINE__, "Check condition failed: " #cond); \
52
abort(); \
53
} \
54
} while(0)
55
61
#ifdef MINISKETCH_VERIFY
62
#define CHECK_SAFE(cond) CHECK(cond)
63
#else
64
#define CHECK_SAFE(cond)
65
#endif
66
72
#ifdef MINISKETCH_VERIFY
73
#define CHECK_RETURN(cond, rvar) do { \
74
if (EXPECT(!(cond), 0)) { \
75
fprintf(stderr, "%s:%d: %s\n"
, __FILE__, __LINE__, "Check condition failed: " #cond); \
76
abort(); \
77
return rvar;
/* Does nothing, but causes compile to warn on incorrect return types. */
\
78
} \
79
} while(0)
80
#else
81
#define CHECK_RETURN(cond, rvar) do { \
82
if (EXPECT(!(cond), 0)) { \
83
return rvar; \
84
} \
85
} while(0)
86
#endif
87
88
#endif
Generated on Sat Aug 22 2026 20:00:35 for Bitcoin Core by
1.9.4