rcx

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

commit bd81806d6b29848da7478def0afd7758608a5a9b
parent 58ec1e65dd8320654ce9ba920f6847270cddc384
Author: Robert Russell <robertrussell.72001@gmail.com>
Date:   Thu, 23 Feb 2023 22:50:57 -0800

Add VA_DEFAULT macro

Diffstat:
Minc/def.h | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/inc/def.h b/inc/def.h @@ -7,6 +7,12 @@ #define JOIN_AUX(a,b) a##b #define JOIN(a,b) JOIN_AUX(a,b) +/* VA_DEFAULT is a helper for writing macros with an optional argument. Usage: + * #define MY_MACRO(...) VA_DEFAULT(,##__VA_ARGS__, "default") + * MY_MACRO() -> "default" + * MY_MACRO("whoa") -> "whoa" */ +#define VA_DEFAULT(_, v, ...) v + #define LEN(a) (sizeof (a) / sizeof (a)[0]) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) @@ -32,7 +38,8 @@ /* Here, roughly speaking, "word" means the largest unit that the machine can * operate on in one instruction (typically the same width as registers and * the bus). This detection is probably wrong on some weird machines, but this - * is the best we can do in C. */ + * is the best we can do in C. + * XXX: Is this used anywhere? We should probably just assume 64 bit. */ #if UINTPTR_MAX == UINT32_MAX #define WORD_SIZE 4 #elif UINTPTR_MAX == UINT64_MAX