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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!uunet.ca!wildcan!sq!msb
  3. From: msb@sq.sq.com (Mark Brader)
  4. Subject: Re: Is this ANSI?
  5. Message-ID: <1992Nov21.125038.26244@sq.sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <9eRguB1w165w@quest.UUCP> <24238@alice.att.com>
  8. Date: Sat, 21 Nov 92 12:50:38 GMT
  9. Lines: 44
  10.  
  11. > > Here is (a simplified version of) the struct that the compiler
  12. > > calls an error:
  13. > > struct FM
  14. > > {
  15. > >     short    data_len;
  16. > >     char    data[];        /*  This line is the kicker  */
  17. > > };
  18.  
  19. I attempted to email an answer to the poster, also pointing out
  20. that his Reply-To line was invalid.  The mail actually did get to
  21. his system, or another one with the same name, but it then bounced
  22. with the message that there was no such user on the machine.  I
  23. will resend the message if the poster can supply a working address.
  24.  
  25.  
  26. What I want to address here is the response from Andrew Koenig
  27. (ark@europa.att.com), which reads in part:
  28.  
  29. > That is, why bother with what looks like an array with no elements?
  30. > What use is it?  The only answer I can think of is that you're intending
  31. > to allocate `extra' memory and then subscript off the end of the array --
  32. > and the standard definitely does not allow that technique, period.
  33.  
  34. Andrew, I'm afraid that *you* are definitely wrong, period.
  35.  
  36. The key word here is "allocate", meaning that the intention is to
  37. do something like
  38.  
  39.     struct FM *p = malloc (sizeof (struct FM) + n);
  40.  
  41. In this situation the standard *does* allow a correctly declared
  42. array element of the struct to be subscripted out of range, as long
  43. as you stay within the malloc()ed area.  This has been discussed
  44. at great length in comp.std.c not too long ago.  The only argument
  45. that it might be illegal in this situation which was not countered
  46. by reference to the standard amounted to saying that they must
  47. have *intended* it to be illegal and didn't get the wording right.
  48. -- 
  49. Mark Brader        "It's practically impossible to keep two separate databases
  50. utzoo!sq!msb         in step for any length of time.  That's true even when one
  51. msb@sq.com         of the `databases' is reality itself."   --Andrew Koenig
  52.  
  53. This article is in the public domain.
  54.