lua-users home
lua-l archive

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


> In lobject.h, the first member of TString (dummy) is used to force
> maximum alignment:
> 
> /*
> ** String headers for string table
> */
> typedef union TString {
>   L_Umaxalign dummy;  /* ensures maximum alignment for strings */
>   struct {
>     CommonHeader;
>     lu_byte reserved;
>     unsigned int hash;
>     size_t len;
>   } tsv;
> } TString;
> 
> My question is, why is this necessary? I looked through the code, but
> couldn't figure this out.

The manual says:

  lua_tolstring returns a fully aligned pointer to a string inside the
  Lua state.

The string itself is stored just after this structure:

  #define getstr(ts)      cast(const char *, (ts) + 1)

-- Roberto