SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
stddef.h
Go to the documentation of this file.
1#ifndef __STDDEF_H__
2#define __STDDEF_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#if defined(__cplusplus)
9#define NULL (0)
10#else
11#define NULL ((void *) 0)
12#endif
13
14#if (defined(__GNUC__) && (__GNUC__ >= 4))
15#define offsetof(type, member) __builtin_offsetof(type, member)
16#else
17#define offsetof(type, field) ((size_t) (&((type *) 0)->field))
18#endif
19#define container_of(ptr, type, member) \
20 ({ \
21 const typeof(((type *) 0)->member) *__mptr = (ptr); \
22 (type *) ((char *) __mptr - offsetof(type, member)); \
23 })
24
25#if (defined(__GNUC__) && (__GNUC__ >= 3))
26#define likely(expr) (__builtin_expect(!!(expr), 1))
27#define unlikely(expr) (__builtin_expect(!!(expr), 0))
28#else
29#define likely(expr) (!!(expr))
30#define unlikely(expr) (!!(expr))
31#endif
32
33#define min(a, b) \
34 ({ \
35 typeof(a) _amin = (a); \
36 typeof(b) _bmin = (b); \
37 (void) (&_amin == &_bmin); \
38 _amin < _bmin ? _amin : _bmin; \
39 })
40#define max(a, b) \
41 ({ \
42 typeof(a) _amax = (a); \
43 typeof(b) _bmax = (b); \
44 (void) (&_amax == &_bmax); \
45 _amax > _bmax ? _amax : _bmax; \
46 })
47#define clamp(v, a, b) min(max(a, v), b)
48
49#define ifloor(x) ((x) > 0 ? (int) (x) : (int) ((x) -0.9999999999))
50#define iround(x) ((x) > 0 ? (int) ((x) + 0.5) : (int) ((x) -0.5))
51#define iceil(x) ((x) > 0 ? (int) ((x) + 0.9999999999) : (int) (x))
52#define idiv255(x) ((((int) (x) + 1) * 257) >> 16)
53
54#define X(...) ("" #__VA_ARGS__ "")
55
56enum {
57 FALSE = 0,
58 TRUE = 1,
59};
60
61#ifdef __cplusplus
62}
63#endif
64
65#endif /* __STDDEF_H__ */
@ FALSE
Definition stddef.h:53
@ TRUE
Definition stddef.h:54