home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3037 < prev    next >
Encoding:
Text File  |  1992-11-19  |  3.5 KB  |  66 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!walter!att-out!pacbell.com!sgiblab!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!news!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  3. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  4. Subject: Re: fwrite+fread of pointer
  5. Message-ID: <1992Nov17.071738.17760@nntpd.lkg.dec.com>
  6. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  7. Reply-To: diamond@jit.dec.com (Norman Diamond)
  8. Organization: Digital Equipment Corporation Japan , Tokyo
  9. References: <15935@goanna.cs.rmit.oz.au> <1992Nov13.101813.163@nntpd.lkg.dec.com> <1992Nov15.065204.22137@sq.sq.com> <15976@goanna.cs.rmit.oz.au>
  10. Date: Tue, 17 Nov 1992 07:17:38 GMT
  11. Lines: 53
  12.  
  13. In article <15976@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
  14. >In article <1992Nov15.065204.22137@sq.sq.com>, msb@sq.sq.com (Mark Brader) writes:
  15. >> First, I take it that everyone agrees that the bytes read back from
  16. >> the file have to be the same ones that were written out.  The question
  17. >> then is whether the bytes that represent the pointer value &dummy have
  18. >> to always be the same ones, during the life of the variable "dummy".
  19.  
  20. >That is indeed the question.
  21.  
  22. Uh, that was my question, and I thought that was your question, but then
  23. you proceed to suggest that your real question was a bit different....
  24.  
  25. >I have been arguing for a while in comp.lang.c that it would be
  26. >a good thing if C compilers were to warn about fwrite(&x... or fread(&x...
  27. >where x is of a type which can include pointers.  I have seen too many
  28. >students get this wrong.  It is a particularly easy mistake to make:
  29. >    struct Tag { ... char field[20]; ... } x;
  30. >    fwrite(&x, sizeof x, 1, f);
  31. >and then the instructor points out that `field' is supposed to hold
  32. >file names and 20 is absurdly small, so the student changes it to
  33. >    struct Tag { ... char *field; ... } x;
  34. >and misses a couple of the fwrite()s.
  35. [...some other argue that it might be useful...]
  36. >[...]is it EVER possible for a _portable_ program to write out a pointer
  37. >and usefully read it back?
  38.  
  39. The ability to write pointers might be useful.  As a pedantic example,
  40. an interpreter might create a core dump of a subject program.  The ability
  41. to write the bytes and read them back is certainly possible and portable.
  42.  
  43. However, you have certainly demonstrated that a warning would be useful,
  44. at least for some users in some cases.  The standard certainly allows such
  45. warnings, and quality of implementation might suggest an option.  It's only
  46. a matter of opinion whether the default have them enabled or disabled.
  47. It seems that this is the question you really wanted to ask, and the
  48. answer seems to be clear enough.
  49.  
  50. >The question can now be paraphrased:  is a pointer like a tensor, or like
  51. >the components of a tensor?  I would regard a compacting garbage collector
  52. >as simply changing the co\"ordinate system.  I have used hardware and
  53. >software systems where stacks could be moved (in order to "stretch" them)
  54. >while the owning thread was running.
  55.  
  56. Well, obviously in virtual memory, and less obviously in some other
  57. addressing techniques, it is possible to move objects and keep existing
  58. pointers meaningful without changing them.  And the C standard doesn't
  59. talk about tensors or components of tensors; an implementation could make
  60. pointers be even more obscure as long as the results are correct.  Now,
  61. how many results have to be guaranteed?  That's the same old hard question.
  62. --
  63. Norman Diamond       diamond@jit081.enet.dec.com
  64. If this were the company's opinion, I wouldn't be allowed to post it.
  65. "It's been a lovely recession."
  66.