From 3f90eff4947ffeb7022696ab9861ed3d80bb61d8 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 18 Jan 2023 12:38:18 +0100 Subject: [PATCH] Add WIDTHOF() to get the width in bits It is common to use the expression 'sizeof(x) * CHAR_BIT' to mean the width in bits of a type or object. Now that there are _WIDTH macros for some types, indicating the number of bits that they use, it makes sense to wrap this calculation in a macro of a similar name. Signed-off-by: Alejandro Colomar --- lib/defines.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/defines.h b/lib/defines.h index d3416f119..5ef11c021 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -169,6 +169,7 @@ static inline void memzero(void *ptr, size_t size) #define SCALE DAY #endif +#define WIDTHOF(x) (sizeof(x) * CHAR_BIT) #define NITEMS(arr) (sizeof((arr)) / sizeof((arr)[0])) /* Copy string pointed by B to array A with size checking. It was originally -- 2.47.2