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