lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Tue, May 14, 2019 at 8:47 PM Jim <djvaios@gmail.com> wrote:
> it seems that a MAX macro for LUA_UNSIGNED is not #defined in luaconf.h
> so that i had to use ULLONG_MAX from <limits.h> directly instead.

you could also use

lua_Unsigned umax = ~ 0 ;

to determine this upper maximum.
this has the advantage that you do not need to know what C integer type
is actually used as Lua integer type.

Doesn't that need to be:

lua_Unsigned umax = ~(lua_Unsigned)0;

to cover all of the cases that the C standard supports? It's been a while since I've had my head that deep in this, but I know that 0 is of type signed int. What I don't remember is if sign extension applies BEFORE or AFTER converting to unsigned; that _expression_ might end up being 0x00000000FFFFFFFF if it converts to unsigned before doing sign extension.

/s/ Adam