home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2616 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  1.3 KB

  1. Path: sparky!uunet!utcsri!dgp.toronto.edu!flaps
  2. Newsgroups: comp.std.c
  3. From: flaps@dgp.toronto.edu (Alan J Rosenthal)
  4. Subject: Re: struct hack, and other out-of-array references
  5. Message-ID: <1992Sep12.164648.10600@jarvis.csri.toronto.edu>
  6. References: <1992Sep07.104932.20060@x.co.uk> <1992Sep8.124655.1498@Urmel.Informatik.RWTH-Aachen.DE> <1992Sep10.014137.16209@sq.sq.com> <1992Sep10.213240.10272@thinkage.on.ca> <1992Sep11.012438.24377@jarvis.csri.toronto.edu> <9225600.28053@mulga.cs.mu.OZ.AU>
  7. Date: 12 Sep 92 20:46:48 GMT
  8. Lines: 17
  9.  
  10. fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  11. >Do same considerations would apply if you tried to use a char[5][5] 
  12. >array as a char[25] array?
  13.  
  14. Actually, I don't think that they do, because along the path to doing this
  15. screwing around you go through a (char *).
  16.  
  17. >From what you're saying, the reason that casting the return
  18. >value from malloc succeeds is only because malloc is "magic".
  19.  
  20. I think the magic of pointer-to-char comes into play too.  Any object can be
  21. traversed by pointers-to-char.  So in your example, in my opinion, you're ok
  22. because the dubious operation occurs with pointers-to-char.
  23.  
  24. Note that you're even guaranteed that the "sizeof" of a char[5][5] array is
  25. exactly 25, because sizeof(char) has to be 1 and an array 5 of something has to
  26. be exactly 5 times the "sizeof".
  27.