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

  1. Path: sparky!uunet!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Aligning an arbitrary pointer?
  5. Date: 23 Jul 1992 05:08:23 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 35
  8. Message-ID: <14les7INN4m@early-bird.think.com>
  9. References: <PDS.92Jul18154500@lemming.webo.dg.com> <14f6u9INNon7@early-bird.think.com> <PDS.92Jul21153918@lemming.webo.dg.com>
  10. NNTP-Posting-Host: gandalf.think.com
  11.  
  12. In article <PDS.92Jul21153918@lemming.webo.dg.com> pds@lemming.webo.dg.com (Paul D. Smith) writes:
  13. >    bm> On some systems, casting a pointer to a more restrictive type
  14. >    bm> may have the effect of realigning it. [...]
  15. >
  16. >Bleah :).  Maybe true, but certainly not Standard practice.  I would
  17. >expect that on at least some systems the compiler will happily allow
  18. >you to assign 0x01381 (or some other non-aligned value) to an int*,
  19. >say, and then just core with a bus error (or otherwise die) when you
  20. >tried to dereference the pointer 
  21.  
  22. I expect so as well.  But since the purpose of my post was to list
  23. useful possibilities, I didn't feel like mentioning all the other kinds of
  24. systems.  That's why I said "on some systems".
  25.  
  26. >    bm> Why not just declare a structure that contains the array and
  27. >    bm> the preceding stuff?  The compiler will guarantee that the
  28. >    bm> array is suitably aligned.
  29. >
  30. >The preceding stuff is of dynamic size; it's read in from a file where
  31. >the file contains the total size and interesting offsets.  The page
  32. >table size has to be dynamic as well.
  33.  
  34. I was wondering whether this was the case.  I came up with an idea, but I'm
  35. not sure whether it really works.
  36.  
  37. Declare the structure as a union, where one case is an array of page table
  38. entries, and the other is the preceding stuff.  Then find the array element
  39. whose address is greater than the address of the end of the preceding
  40. stuff.  Use the address of that array element as the address of the page
  41. table.
  42. -- 
  43. Barry Margolin
  44. System Manager, Thinking Machines Corp.
  45.  
  46. barmar@think.com          {uunet,harvard}!think!barmar
  47.