[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (rc1) now available
- From: Patrick Rapin <toupie300@...>
- Date: Fri, 25 Nov 2011 16:09:09 +0100
> 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