home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2351 next >
Encoding:
Text File  |  1992-07-21  |  1.7 KB  |  39 lines

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