lua-users home
lua-l archive

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


> The problem is that this cast is not completely useless.  In 32-bit
> machines with lua_Integer defined as long long, the compiler will
> generate more expensive code for nothing.  Moreover, we want to shift
> an 'int'. We do not want to shift 64 bits, despite what the compiler
> thinks.  Isn't there any way to indicate that fact in the code so that
> it will not generate warnings?

Maybe. If your concern is that lua_Integer may be bigger than the
machine word size, we may replace lua_Integer with another type which
is exactly the size of that word, like ptrdiff_t.
The following works for me:

#define twoto(x)	((ptrdiff_t)1<<(x))

It is also possible to cast the result rather than the operand. The
following produces no warning neither on my system:

#define twoto(x)	(ptrdiff_t)(1<<(x))

At the extreme case, we can simply turn off the warning. I do not like
this solution of course:

#ifdef _MSC_VER
#pragma warning(disable:4334)
#endif