-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternal.h
More file actions
31 lines (25 loc) · 1.06 KB
/
internal.h
File metadata and controls
31 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - __builtin_offsetof(type,member) );})
#define S(x) #x
#define S_(x) S(x)
#define S__LN__ S_(__LINE__)
#define __log(...) do { fprintf(stderr, __VA_ARGS__); } while (0)
#define log(...) do { __log(__FILE__ ":" S__LN__ ": " __VA_ARGS__); } while (0)
#define warn(...) do { log("WARNING: " __VA_ARGS__); } while (0)
#define fatal(...) do { log("FATAL: " __VA_ARGS__); abort(); } while (0)
#define BUG_ON(c) \
do { if (__builtin_expect(c, 0)) fatal("BUG: " #c "\n"); } while (0)
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)