home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!wupost!darwin.sura.net!convex!constellation!munnari.oz.au!metro!mama!andy
- From: andy@research.canon.oz.au (Andy Newman)
- Subject: Re: Variable length records
- Message-ID: <Bs6GH9.AxF@research.canon.oz.au>
- Sender: news@research.canon.oz.au
- Organization: Canon Information Systems Research Australia
- References: <24137@castle.ed.ac.uk> <rbjmzg-.gurgle@netcom.com> <1992Jul25.091702.15993@klaava.Helsinki.FI>
- Date: Thu, 30 Jul 1992 01:07:56 GMT
- Lines: 32
-
- wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
- >My gcc 2.2.2 under Linux doesn't seem to support it, at least with the
- >default options:
-
- GCC uses 0 length arrays for this... from the manual...
-
- Arrays of Length Zero
- =====================
-
- Zero-length arrays are allowed in GNU C. They are very useful as
- the last element of a structure which is really a header for a
- variable-length object:
-
- struct line {
- int length;
- char contents[0];
- };
-
- {
- struct line *thisline = (struct line *)
- malloc (sizeof (struct line) + this_length);
- thisline->length = this_length;
- }
-
- In standard C, you would have to give `contents' a length of 1,
- which means either you waste space or complicate the argument to
- `malloc'.
-
-
-
- --
- Andy Newman (andy@research.canon.oz.au) "Int. God's own type"
-