Suitably aligned pointers

Richard Harter g-rh at XAIT.Xerox.COM
Sat Oct 15 18:54:01 AEST 1988


In article <345 at marob.MASA.COM> daveh at marob.UUCP (Dave Hammond) writes:
>We use a pretty basic set of memory management routines which
>allocate large hunks of memory and parcel it out as requested,
>saving malloc the headache of managing huge lists of small buffers.
>The problem is the routines don't return a `suitably aligned' pointer,
>so the accuracy of casting the return to other than char * is in doubt.

>Can someone explain the technique used to suitably align a pointer ?

"suitably aligned" is a machine dependent notion.  On any given machine
there are address restrictions associated with operations on particular
kinds of primitive objects for the machine.  For example, a move double
word instruction may require that the addresses be even word boundaries.
Malloc returns suitably aligned pointers.  In practice a char pointer
whose offset from a malloc supplied pointer is divible by 8 will also
be suitably aligned.  More generally, replace 8 by the width of a double
in bytes.  This is not guaranteed, but it is pretty safe.  
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list