From ef5d171cc89b19ac1fea905b99d819b5f97cba00 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 27 Mar 2025 12:38:29 -0300 Subject: New macro 'l_numbits' --- llimits.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'llimits.h') diff --git a/llimits.h b/llimits.h index d206e9e1..710dc1b4 100644 --- a/llimits.h +++ b/llimits.h @@ -15,6 +15,8 @@ #include "lua.h" +#define l_numbits(t) cast_int(sizeof(t) * CHAR_BIT) + /* ** 'l_mem' is a signed integer big enough to count the total memory ** used by Lua. (It is signed due to the use of debt in several @@ -33,7 +35,7 @@ typedef unsigned long lu_mem; #endif /* } */ #define MAX_LMEM \ - cast(l_mem, (cast(lu_mem, 1) << (sizeof(l_mem) * 8 - 1)) - 1) + cast(l_mem, (cast(lu_mem, 1) << (l_numbits(l_mem) - 1)) - 1) /* chars used as small naturals (so that 'char' is reserved for characters) */ @@ -61,7 +63,7 @@ typedef lu_byte TStatus; ** floor of the log2 of the maximum signed value for integral type 't'. ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) */ -#define log2maxs(t) cast_int(sizeof(t) * 8 - 2) +#define log2maxs(t) (l_numbits(t) - 2) /* -- cgit v1.2.3-55-g6feb