[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUAI_USER_ALIGNMENT_T
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 03 Nov 2005 09:31:55 -0200
> 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