[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange error with 5.4 random generator on old compiler
- From: Steffen Nurpmeso <steffen@...>
- Date: Sat, 03 Dec 2022 21:54:53 +0100
All best wishes, Pelé!
Mouse wrote in
<202212030051.TAA05134@Stone.Rodents-Montreal.ORG>:
|>> #define LUA_MAXINTEGER 0x7fffffffffffffff
|>> #define LUA_MININTEGER (-0x8000000000000000)
|>> #define LUA_MAXUNSIGNED 0xffffffffffffffff
|
|> How can that work without ull and ll suffix, it required
|> "__extension__ X ## ull" and such macros to get it done with gcc
|> 2.95(.2?) for sure. It really does??
|
|Well, I'm not sure. It definitely doesn't work in the preprocessor;
Well ... just forget about it. Looking at it i wonder that
#else /* no 'Rand64' }{ */
...
#define trim32(x) ((x) & 0xffffffffu)
never caused any trouble reports in the !LUAI_IS32INT case.
I surely have seen compiler/versions that would have wanted to see
a lu suffix or at least warned. The same for lua.h's
typedef LUA_INTEGER lua_Integer;
i have had, for example,
#else .. !64-bit
__SF_CC_INT8 typedef unsigned __SF_INT8 ui8;
__SF_CC_INT8 typedef signed __SF_INT8 si8;
where CC_INT8 would become __extension__ and INT8 would be long
long int, for example, in your environment (or gcc/g++ 2.92., to
be exact). Yes, the configuration script figured out "64-bit".
We did not use limits.h. So no idea how to easily adjust
#elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
(ie LUA_MAXUNSIGNED must not be used in preprocessor at all).
I think i would, since limits.h is included by luaconf.h, adjust
the one use case in src/lmathlib.c:project() from preprocessor to
compiler, removing one source of problems. This also to follow
the great ones from Bell Labs in their desire to leave everything
up to the compiler. (Plan9 compiler manual, written by Kernighan
i think, is always worth a read, i think the statement is in
there, but i also read it from McIlroy.)
For the other one i think i would go for LONG_MAX and INT_MAX,
which surely are both usable in preprocessor; from
#if !defined(LUA_RAND32) && !defined(Rand64)
/* try to find an integer type with at least 64 bits */
# if (ULONG_MAX >> 31 >> 31) >= 3
/* 'long' has at least 64 bits */
# define Rand64 unsigned long
# elif !defined(LUA_USE_C89) && defined(LLONG_MAX)
/* there is a 'long long' type (which must have at least 64 bits) */
# define Rand64 unsigned long long
# elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
/* 'lua_Integer' has at least 64 bits */
# define Rand64 lua_Unsigned
# endif
#endif
to
#if !defined(LUA_RAND32) && !defined(Rand64)
/* try to find an integer type with at least 64 bits */
# if LUAI_IS32INT && LONG_MAX != INT_MAX
/* 'long' has at least 64 bits */
# define Rand64 unsigned long
# elif defined(LUA_USE_WINDOWS)
/* 'lua_Integer' is __int64 */
# define Rand64 lua_Unsigned
# elif !defined(LUA_USE_C89) && defined(LLONG_MAX)
/* there is a 'long long' type (which must have at least 64 bits) */
# define Rand64 unsigned long long
Otherwise LUA_MAXUNSIGNED is definetely not 64-bit!?
# endif
#endif
So with these changes no more preprocessor arithmetic on that.
Have a nice weekend, if you can.
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)