lua-users home
lua-l archive

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


> Is there a special reason why, in luaconf.h,
> LUAI_USER_ALIGNMENT_T is #defined as
> 
>    union { double u; void *s; long l; }
> 
> rather than as
> 
>    union { LUA_NUMBER u; void *s; long l; }
> 
> ?

That union is never accessed in the code, so the use of a double should
not generate unnecessary loads and stores. Its only purpose is to ensure
proper alignment. In "small" machines, doubles do not have special
requirements for alignment, so its presence there should not affect the
code.

It is not uncommon to install Lua with a smaller/cheapter number type
and to use userdata to implement doubles (and/or to use doubles inside
other kinds of userdata). In those cases, it is essential that a
userdata buffer has a proper double alignment.

-- Roberto