[MLton] x86_64 port status

skaller skaller@users.sourceforge.net
Wed, 10 May 2006 18:49:42 +1000


On Wed, 2006-05-10 at 09:25 +0300, Vesa Karvonen wrote:
> Quoting skaller <skaller@users.sourceforge.net>:
> > On Tue, 2006-05-09 at 16:31 -0700, Stephen Weeks wrote:
> > > > Perhaps a better approach would be to define the following:
> > > > 
> > > >    struct PointerAux { unsigned char[4]; } __attribute__ ((aligned (4));
> > > >    typedef struct PointerAux* Pointer;
> > > 
> > > I tried this out and it worked well.  To be clear, I used
> > > 
> > >   struct PointerAux { unsigned char z[4]; } __attribute__ ((aligned (4)));
> > 
> > But this only works for gcc! Please use a union to align
> > data, it's portable to all compilers and architectures.
> 
> Sorry, I haven't followed this discussion closely.  Do you mean
> a union like below?
> 
>   union PointerAux {
>      char c;
>      short s;
>      int i;
>      long l;
>      /* ... where all types have sizeof <= 4 */
>   };
> 
> -Vesa Karvonen

Something like that, yes .. depending on what the purpose
of PointerAux is. Maybe something like:

union X {
	unsigned long i;
	unsigned char a[
		sizeof long> sizeof(void*)? 
		sizeof long : 
		sizeof (void*)
	];
	void *p;
};

which aligns for both long and pointer, and also gives
byte by byte access to the longest of the two.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net