[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: snapshot of Lua 4.1 (work)
- From: David Jones <djones@...>
- Date: Fri, 11 May 2001 08:31:31 +0000
In message <001d01c0d9cc$24d21f40$8402a8c0@johndell>, "John Belmonte" writes:
> Roberto wrote:
> > > union L_Umaxalign { double d; void *s; long l; };
> > >
> > > should probably be:
> > >
> > > union L_Umaxalign { lua_Number d; void *s; long l; };
> >
> > This double is to ensure proper alignment for userdata and strings
> > *outside* Lua. (Notice that strings will always be aligned, too.)
> [deletia]
> Anyway, I think that union is not generally sufficient. On my machine the
> largest data type requiring alignment is 16 bytes (a vector). (By no
> coincidence this is also the alignment of the stack and heap.) Maybe you
> could make it a build option, something like:
>
> #ifdef LUA_ALIGNMENT
> union L_Umaxalign { char[LUA_ALIGNMENT]; };
> #else
> union L_Umaxalign { double d; void *s; long l; };
> #endif
No, because a char[n] array for some n won't allow you to guarantee any
particular alignment (though it may be true for your architecture that a
char[16] is always 16 byte aligned). If the user wants to override the
alignment union then they need to specify a type:
#ifdef LUSER_ALIGNMENT_T
union L_Umaxalign { LUSER_ALIGNMENT_T luser_dummy_member; };
#else
...
(Thank goodness for typedef).
Cheers,
drj