[M3devel] fewer wrappers/more C? (or a wash?)

Jay jay.krell at cornell.edu
Mon Apr 20 16:51:52 CEST 2009


> 1. Some heap objects have to be aligned because they contain a field or
> element
> that must be aligned. Examples are an open array of INTEGER and a
> linked-list node that contains a pointer. And,


And on every system there exist fields/elements that really require alignment?
 

The following works fine for me..x86 tends to be very lax on requiring any alignment.
 

#include 
 
 
int main()
{
unsigned char a[20];
unsigned i;
 

for (i = 0 ; i < 20 ; ++i)
 a[i] = (unsigned char)i;
 

for (i = 0 ; i < 8 ; ++i)
 printf("%x\n", *(unsigned*)&a[i]);

for (i = 0 ; i < 8 ; ++i)
 printf("%f\n", *(double*)&a[i]);

return 0;
}
 

I think we only care about Modula-3 heap allocated pointers, so what
folks do in their C code doesn't matter.
We can even introduce and depend upon higher alignment than the hardware requires
or the underlying allocator provides.
 

I realize that SPARC, MIPS, maybe Alpha, ARM?, IA64, and probably others,
do have hardware-enforced alignment requirements.
(Having debugged some of them.)
 
 
I'm mostly just causing trouble.
The proposals are all somewhat dangerous, but in reality they are ok,
and can buy significant efficiencies in certain applications.
Alignment is normal, even on x86.
 
 
Btw, presumably on a 64 bit system, you can get a 32bit float in one of these things.
 
 
 
 - Jay


More information about the M3devel mailing list