[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Please help: do lua sources assume a 32-bit int?
- From: Ben Sunshine-Hill <sneftel@...>
- Date: Mon, 31 Jan 2005 00:29:32 -0800
That code looks fine. It'll work with int sizes up to 32 bits, but it
doesn't assume them. That part of the conditional handles ints bigger
than the 16-bit maxint, and simply won't ever be executed on a
16-bit-int machine.
IIRC, there are people using Lua on 16-bit embedded systems with no
problems at all.
Ben
On Mon, 31 Jan 2005 09:52:27 +0200, Bogdan Marinescu
<bogdan.marinescu@gmail.com> wrote:
> (This was first posted on the forum; i'm reposting it here with the
> hope of a shorter response time)
>
> Hello all,
>
> I'm trying to compile lua 5.0.2 for a CPU that has sizeof(int)==2,
> instead of 4. While trying to compile the lua core, I got the
> following warning:
>
> [Warning(ccom):lobject.c,line 62] this comparison is always false
> ===> if (x >= 0x00010000) {
> [Warning(ccom):lobject.c,line 63] this comparison is always false
> ===> if (x >= 0x01000000) return log_8[((x>>24) & 0xff) - 1]+24;
>
> Looking in lobject.c, this is what I found:
>
> Code:
> int luaO_log2 (unsigned int x) {
> static const lu_byte log_8[255] = {
> 0,
> 1,1,
> 2,2,2,2,
> 3,3,3,3,3,3,3,3,
> 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
> 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
> 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
> 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
> 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
> 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
> 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
> 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
> };
> if (x >= 0x00010000) {
> if (x >= 0x01000000) return log_8[((x>>24) & 0xff) - 1]+24;
> else return log_8[((x>>16) & 0xff) - 1]+16;
> }
> else {
> if (x >= 0x00000100) return log_8[((x>>8) & 0xff) - 1]+8;
> else if (x) return log_8[(x & 0xff) - 1];
> return -1; /* special `log' for 0 */
> }
> }
>
> Ar the first glance, this piece of code seems to indicate that the
> size of int is always 32 bits. Is this the case? If so, are there more
> places in the source where this happens? If they are, I'll have to
> define some custom types and modify the code (write everywhere 'u32'
> instead of 'unsigned int', for example, where 'u32' is an user defined
> type).
> Thank you very much for your help,
>
> Bogdan M.
>