home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2353 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  1.5 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!mips!pacbell.com!decwrl!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Aligning an arbitrary pointer?
  5. Message-ID: <14005@ksr.com>
  6. Date: 21 Jul 92 12:08:18 EDT
  7. References: <PDS.92Jul16111642@lemming.webo.dg.com> <1473f4INNq24@early-bird.think.com> <PDS.92Jul18154500@lemming.webo.dg.com> <1992Jul20.152052.329@jarvis.csri.toronto.edu>
  8. Sender: news@ksr.com
  9. Lines: 17
  10.  
  11. flaps@dgp.toronto.edu (Alan J Rosenthal) writes:
  12. [ make a union of everything and use its size as the magic pessimal alignment
  13.  constant ]
  14. >The existence of this constant is the remaining issue.  I don't think that
  15. >anything in the standard mandates that this exists; for example, suppose the
  16. >rule was that all pointers, ints, longs, etc had to be aligned on an *odd*
  17. >word?  But I'd be awfully surprised if such a machine existed.
  18.  
  19. I *think* that the standard requires alignment to get worse, so that odd word
  20. alignment wouldn't be legal, but I'm not sure.  However, there's still a
  21. fundamental problem -- in order to round up a random pointer in this manner,
  22. you need to perform integer arithmetic on it, not pointer arithmetic.  The
  23. standard makes too few guarantees about what happens when you turn pointers
  24. into integers and vice versa.  If you have an array of char whose base you
  25. *know* is maximally aligned (eg it came from malloc (the title of a horror
  26. film?)), then you can re-align pointers within the array if you have the
  27. base pointer handy.
  28.