lua-users home
lua-l archive

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


(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.