lua-users home
lua-l archive

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

int type.
Varies enormously on various platforms, with 32 bits on almost all and 64 bits on some.
See at:

We have a string with more than 4GB, in pointers (64 bits) "const char * conv" and "char * buff" .
The convlen size is int (32 bits).

int memcmp ( const void * ptr1, const void * ptr2, size_t num )
void * memcpy ( void * destination, const void * source, size_t num );

Both expect size_t, as a length parameter (num).
oplen is declared as int type.

While int addresses all the need for options, correcting convlen,
oplen is compared to convlen and used as the index of a string (size_t),
the appropriate type of which is used is size_t or ptrdiff_t.

      return conv + oplen;  /* pointer arithmetic with int type */

#include <stdio.h>
int main()
   printf ("sizeof(size_t)=%llu\n", sizeof(size_t));
   printf ("sizeof(int)=%llu\n", sizeof(int));
   return 0;

Thus, the code follows good programming practices in C, and becomes 64-bit compatible.

Ranier Vilela