home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17045 < prev    next >
Encoding:
Text File  |  1992-11-23  |  2.7 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!sasghm
  3. From: sasghm@theseus.unx.sas.com (Gary Merrill)
  4. Subject: Re: Is this ANSI?
  5. Originator: sasghm@theseus.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <By6K81.KuF@unx.sas.com>
  8. Date: Mon, 23 Nov 1992 17:50:25 GMT
  9. References: <24238@alice.att.com> <1992Nov21.125038.26244@sq.sq.com> <24270@alice.att.com> <1992Nov23.090611.3209@sq.sq.com>
  10. Nntp-Posting-Host: theseus.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 44
  13.  
  14.  
  15. Well, I think I've switched sides on this one -- however goofy I
  16. think the result is in practice.
  17.  
  18. In article <1992Nov23.090611.3209@sq.sq.com>, msb@sq.sq.com (Mark Brader) writes:
  19. |> > Now, look back at the assertion I asked you to remember.  I expect
  20. |> > that Mark Brader is going to say `But p->data isn't an array of
  21. |> > one element, it's an array of 101 elements.  After all, when you
  22. |> > said malloc(sizeof(struct FM + 100), you allocated enough memory
  23. |> > for 101 elements!'
  24. |> 
  25. |> No, I'm not.  That would be wrong for the reasons you said.  What I
  26. |> did say was that while the character pointed to by the decayed
  27. |> pointer p->data is indeed part of the one-character array p->data,
  28. |> it is *also* part of a larger array, namely the object returned by
  29. |> malloc(), whose size might be, say, 104 elements when considered
  30. |> as an array of char.  Therefore the Unless clause is applicable
  31. |> and the reference valid.
  32.  
  33. But there is no larger array.  There is a contiguous block of memory
  34. returned by malloc(), but this is *not* an array in the technical sense
  35. that 'array' is used in the standard.  The pointer p->data indeed
  36. points to a position in this block of memory, and p->data is an array,
  37. but (unforutnately?) it does *not* follow that p->data[5] is legitimate
  38. since the only *array* in question is only 1 byte in length.
  39.  
  40. I think this exposes some sloppiness in the use of "array" at places
  41. in the standard.  Since in fact malloc() returns a 'void *', it is
  42. hard to construe the block allocated as an array (of what?).  You
  43. can proceed to *look at* this block as an array.  But you *can't*
  44. (strictly speaking) look at it as "the array p->data" because, I
  45. would argue, 'p->data' is not a modifiable lvalue.  The p->data array
  46. (of one element) may *overlap* a larger array, but it still doesn't
  47. follow that you can index off the end of p->data into that larger
  48. array *by using 'p->data'*.
  49.  
  50. This consequence may be counterintuitive initially, but it doesn't
  51. appear to be inconsistent.
  52.  
  53.  
  54. -- 
  55. Gary H. Merrill  [Principal Systems Developer, C Compiler Development]
  56. SAS Institute Inc. / SAS Campus Dr. / Cary, NC  27513 / (919) 677-8000
  57. sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
  58.