diff options
Diffstat (limited to 'macros.h')
| -rw-r--r-- | macros.h | 51 |
1 files changed, 27 insertions, 24 deletions
@@ -1,22 +1,25 @@ #ifndef macros_h #define macros_h +/* #undef assert -#define assert(expr) if (!(expr)) { *(int *)0 = 0; } +#define assert(expr) if (!(expr)) { *(int *)0 = 0; } +*/ +#include <assert.h> -#define array_count(array) (sizeof(array)/sizeof(*(array))) +#define array_count(array) (sizeof(array)/sizeof(*(array))) #undef offsetof -#define offsetof(type, element) ((u64)(&(((type *)0)->element))) +#define offsetof(type, element) ((u64)(&(((type *)0)->element))) -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#define max(a, b) (((a) > (b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) #define clamp(a, x, b) \ - (((x) < (a)) ? (a) : \ - (((x) > (b)) ? (b) : (x))) + (((x) < (a)) ? (a) : \ + (((x) > (b)) ? (b) : (x))) -#define swap(type, a, b) { type tmp = (a); (a) = (b); (b) = tmp; } +#define swap(type, a, b) { type tmp = (a); (a) = (b); (b) = tmp; } #define kilobytes(n) n*1024 #define megabytes(n) kilobytes(n)*1024 @@ -24,27 +27,27 @@ /* NOTE(pryazha): Singly linked list */ #define sllpush(first, last, node) \ - ((first) == 0 ? \ - ((first) = (last) = (node), (node)->next = 0) : \ - ((last)->next = (node), (last) = (node), (node)->next = 0)) + ((first) == 0 ? \ + ((first) = (last) = (node), (node)->next = 0) : \ + ((last)->next = (node), (last) = (node), (node)->next = 0)) #define sllpop(first, last) \ - ((first) == (last) ? \ - ((first) = (last) = 0) : \ - ((first) = (first)->next)) + ((first) == (last) ? \ + ((first) = (last) = 0) : \ + ((first) = (first)->next)) /* NOTE(pryazha): Doubly linked list */ #define dllpush(first, last, node, next, prev) \ - ((first) == 0 ? \ - ((first) = (last) = (node), (node)->next = (node)->prev = 0) : \ - ((node)->prev = (last), (last)->next = (node), (last) = (node), (node)->next = 0)) -#define dllpushback(first, last, node) dllpush(first, last, node, next, prev) -#define dllpushfront(first, last, node) dllpush(last, first, node, prev, next) + ((first) == 0 ? \ + ((first) = (last) = (node), (node)->next = (node)->prev = 0) : \ + ((node)->prev = (last), (last)->next = (node), (last) = (node), (node)->next = 0)) +#define dllpushback(first, last, node) dllpush(first, last, node, next, prev) +#define dllpushfront(first, last, node) dllpush(last, first, node, prev, next) #define dllremove(first, last, node) \ - ((first) == (node) ? \ - ((first) == (last) ? (first) = (last) = 0 : \ - ((first) = (first)->next, (first)->prev = 0)) : \ - ((last) == (node) ? ((last) = (last)->prev, (last)->next = 0) : \ - ((node)->next->prev = (node)->prev, (node)->prev->next = (node)->next))) + ((first) == (node) ? \ + ((first) == (last) ? (first) = (last) = 0 : \ + ((first) = (first)->next, (first)->prev = 0)) : \ + ((last) == (node) ? ((last) = (last)->prev, (last)->next = 0) : \ + ((node)->next->prev = (node)->prev, (node)->prev->next = (node)->next))) #endif |
