From d3823951b5fbc8adb1909395b336c913378a6db0 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 30 May 2020 23:45:29 +0200 Subject: [PATCH] Add M_BOOL_OPLIST --- README.md | 5 +++++ m-core.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index e4504bb9..46596ae0 100644 --- a/README.md +++ b/README.md @@ -599,6 +599,7 @@ Example: My type is: +* a C boolean: M\_BOOL\_OPLIST (M\_DEFAULT\_OPLIST also works) * a C integer or a C float: M\_DEFAULT\_OPLIST (it can also be ommited), * a pointer to something: M\_PTR\_OPLIST, * a plain structure that can be init/copy/compare with memset/memcpy/memcmp: M\_POD\_OPLIST, @@ -5519,6 +5520,10 @@ than a 'size\_t'. Return the associated method to the given operator within the given oplist. +##### M\_BOOL\_OPLIST + +Default oplist for C standard boolean. + ##### M\_DEFAULT\_OPLIST Default oplist for C standard types (int & float) diff --git a/m-core.h b/m-core.h index 8e79de31..aa7c9107 100644 --- a/m-core.h +++ b/m-core.h @@ -2276,6 +2276,8 @@ m_core_hash (const void *str, size_t length) #define M_SUB_DEFAULT(a,b,c) ((a) = (b) - (c)) #define M_MUL_DEFAULT(a,b,c) ((a) = (b) * (c)) #define M_DIV_DEFAULT(a,b,c) ((a) = (b) / (c)) +#define M_AND_DEFAULT(a,b,c) ((a) = (b) & (c)) +#define M_OR_DEFAULT(a,b,c) ((a) = (b) | (c)) #define M_NO_EXT_ALGO(n,co,to) #define M_INC_ALLOC_DEFAULT(n) (M_MAX(8, (n))*2) @@ -2367,6 +2369,14 @@ m_core_hash (const void *str, size_t length) HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) ) #endif +/* Specialized oplist for a boolean. + * M_DEFAULT_OPLIST is nearly ok, except for ADD/SUB/MUL/DIV + * that generates warnings with boolean. + */ +#define M_BOOL_OPLIST \ + M_OPEXTEND(M_DEFAULT_OPLIST, ADD(M_OR_DEFAULT), MUL(M_AND_DEFAULT), \ + SUB(0), DIV(0)) + /* Default oplist for standard types of pointers. */ #define M_PTR_OPLIST \