home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16817 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.7 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!dptg!ulysses!allegra!alice!ark
  2. From: ark@alice.att.com (Andrew Koenig)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is this ANSI?
  5. Message-ID: <24238@alice.att.com>
  6. Date: 19 Nov 92 13:33:50 GMT
  7. Article-I.D.: alice.24238
  8. References: <9eRguB1w165w@quest.UUCP>
  9. Reply-To: ark@alice.UUCP ()
  10. Organization: AT&T Bell Laboratories, Murray Hill NJ
  11. Lines: 32
  12.  
  13. In article <9eRguB1w165w@quest.UUCP> srhqla!quest!kdq writes:
  14.  
  15. >     Here is (a simplified version of) the struct that the compiler
  16. > calls an error:
  17.  
  18. > struct FM
  19. > {
  20. >     short    data_len;
  21. >     char    data[];        /*  This line is the kicker  */
  22. > };
  23.  
  24. >     As I recall, ANSI says this is legal, with sizeof( struct FM) is 2 
  25. > bytes, and offsetof( struct FM, data) is 2.
  26.  
  27. I don't think you recall correctly.  If nothing else, there is no
  28. requirement that sizeof(short) <= 2.  Moreover, since every object,
  29. including members of structures, must have nonzero size, the line
  30. in question would have to allocate at least one element.  I would
  31. therefore expect that if I hunted through my copy of the Standard,
  32. I would find that this fragment is indeed illegal.
  33.  
  34. I'm not going to bother to hunt, though, because I think your question
  35. conceals a more important question that I can answer much more easily.
  36. The point is to ask why you're trying to do this in the first place.
  37.  
  38. That is, why bother with what looks like an array with no elements?
  39. What use is it?  The only answer I can think of is that you're intending
  40. to allocate `extra' memory and then subscript off the end of the array --
  41. and the standard definitely does not allow that technique, period.
  42. -- 
  43.                 --Andrew Koenig
  44.                   ark@europa.att.com
  45.