Article View: comp.std.c
Article #104Re: Aligning an arbitrary pointer?
From: Jim Patterson
Date: Tue, 21 Jul 1992 13:26
Date: Tue, 21 Jul 1992 13:26
27 lines
1798 bytes
1798 bytes
meissner@osf.org (Michael Meissner) writes: : In article <1992Jul20.210212.2935@cognos.com> jimp@cognos.com (Jim : Patterson) writes: : : | I don't know of any way to do this that's guaranteed to work, but it : | can be done for any compiler where casting a pointer to an int : : Of course, if you ever want your code to run on Alpha, you had better : cast the pointer to LONG and not INT. On them new fangled 64-bit : alpha's, ints are 32 bits, longs are 64 bits, and pointers are 64 : bits. No, it doesn't matter. Only the low-order few bits are relevant in the (int)-cast version of the pointer, since it's just used to determine the amount of "unalignment", which is used to build an adjustment to add to the original pointer. I believe it will even work on an AS/400, where pointers are 16 bytes but there is no integer datatype larger than 4 bytes in length. (On the AS/400, casting a pointer to an int returns the offset but drops the segment info etc., but the algorithm is only interested in the offset anyways so doesn't care). The only really troublesome cases are where the alignment size is not a power of two, but fortunately such machines are becoming increasingly rare. -- Jim Patterson Cognos Incorporated Sr Consulting Engineer P.O. BOX 9707 UUNET:jimp@cognos.COM 3755 Riverside Drive PHONE:(613)738-1338 x3385 Ottawa, Ont K1G 3Z4
Technical Details
Message-ID:
<1992Jul21.132654.5668@cognos.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!cognos!jimpReferences:
<MEISSNER.92Jul20225420@curley.osf.org>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!cognos!jimp From: jimp@cognos.com (Jim Patterson) Subject: Re: Aligning an arbitrary pointer? Message-ID: <1992Jul21.132654.5668@cognos.com> Organization: Cognos Incorporated, Ottawa CANADA X-Newsreader: Tin 1.1 PL3 References: <MEISSNER.92Jul20225420@curley.osf.org> Date: Tue, 21 Jul 1992 13:26:54 GMT Lines: 27