lua-users home
lua-l archive

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


> Sure, this applies to C strings. But, luaV_concat() may create a
> string of MAX_SIZET length. And realloc()'s API allows it, too.
> Maybe libc's memory allocator saves you and disallows that, but I
> wouldn't count on it.

I was assuming that ptrdiff_t should be large enough to keep the size of
any C object, given that you can always subtract its last index from its
first index. But the standard simply says that ptrdiff_t is basically
useless:

  In other words, if the expressions P and Q point to, respectively,
  the i-th and j-th elements of an array object, the expression (P)-(Q)
  has the value i-j PROVIDED THE VALUE FITS IN AN OBJECT OF TYPE
  PTRDIFF_T.

(My emphasis.)


> Using MAX_SIZET/2 is probably safer, but too limiting for 16 bit
> platforms (some have a 16 bit size_t and a 32 bit ptrdiff_t).

Maybe ptrdiff_max would be more appropriate.

-- Roberto