rcx

library of miscellaneous bits of C code
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

commit ae8e306e4c19015767a8b50cb3ceafffab4d3f2d
parent 4fbb7f100122a0b189d4218bde0e0d0a9cf4945e
Author: Robert Russell <robertrussell.72001@gmail.com>
Date:   Thu, 25 May 2023 20:48:09 -0700

Add SWAP macro

Diffstat:
Minc/alloc.h | 2+-
Minc/def.h | 7+++++++
2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/inc/alloc.h b/inc/alloc.h @@ -26,4 +26,4 @@ int r_ereallocz(void *p, usize osize, usize nsize); int r_ereallocn(void *p, usize len, usize size); int r_ereallocnz(void *p, usize olen, usize nlen, usize size); -void free(void *p); +void free(void *p); diff --git a/inc/def.h b/inc/def.h @@ -18,6 +18,13 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define SWAP(a, b) do { \ + u8 r_swap_temp_[sizeof(a) == sizeof(b) ? (isize)sizeof(a) : -1]; \ + memcpy(&r_swap_temp_, &(a), sizeof(a)); \ + memcpy(&(a), &(b), sizeof(a)); \ + memcpy(&(b), &r_swap_temp_, sizeof(a)); \ + } while(0) + #ifdef __GNUC__ #define NOINLINE __attribute__((noinline)) #define UNUSED __attribute__((unused))