[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about the TKey union definition
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 17 Feb 2014 09:51:45 -0300
> Hi all,In Lua 5.1.4 source,the Tkey union definition is:
> 323 typedef union TKey {
> 324 struct {
> 325 TValuefields;
> 326 struct Node *next; /* for chaining */
> 327 } nk;
> 328 TValue tvk;
> 329 } TKey;
>
> and the TValue definition is:
> 73 typedef struct lua_TValue {
> 74 TValuefields;
> 75 } TValue;
>
> so my question is, why just define TKey union like this:
> typedef struct TKey {
> TValue tvk;
> struct Node *next;
> } Tkey;
>
> ?
Because of alignment, the size of a 'TValue' can be larger than the size
of its elements. (That code in Lua is particularly relevant in a 32-bit
machine that aligns 'double' in 8-byte boundaries.)
-- Roberto