home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: Is this ANSI?
- Message-ID: <1992Nov21.125038.26244@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <9eRguB1w165w@quest.UUCP> <24238@alice.att.com>
- Date: Sat, 21 Nov 92 12:50:38 GMT
- Lines: 44
-
- > > 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 */
- > > };
-
- I attempted to email an answer to the poster, also pointing out
- that his Reply-To line was invalid. The mail actually did get to
- his system, or another one with the same name, but it then bounced
- with the message that there was no such user on the machine. I
- will resend the message if the poster can supply a working address.
-
-
- What I want to address here is the response from Andrew Koenig
- (ark@europa.att.com), which reads in part:
-
- > 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, I'm afraid that *you* are definitely wrong, period.
-
- The key word here is "allocate", meaning that the intention is to
- do something like
-
- struct FM *p = malloc (sizeof (struct FM) + n);
-
- In this situation the standard *does* allow a correctly declared
- array element of the struct to be subscripted out of range, as long
- as you stay within the malloc()ed area. This has been discussed
- at great length in comp.std.c not too long ago. The only argument
- that it might be illegal in this situation which was not countered
- by reference to the standard amounted to saying that they must
- have *intended* it to be illegal and didn't get the wording right.
- --
- Mark Brader "It's practically impossible to keep two separate databases
- utzoo!sq!msb in step for any length of time. That's true even when one
- msb@sq.com of the `databases' is reality itself." --Andrew Koenig
-
- This article is in the public domain.
-