Path: utzoo!utgpu!attcan!uunet!yale!husc6!xait!g-rh From: g-rh@XAIT.Xerox.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Suitably aligned pointers Message-ID: <35120@XAIT.Xerox.COM> Date: 15 Oct 88 08:54:01 GMT References: <345@marob.MASA.COM> Reply-To: g-rh@XAIT.Xerox.COM (Richard Harter) Organization: Xerox Corporation, Cambridge, Massachusetts Lines: 22 In article <345@marob.MASA.COM> daveh@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.