home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11802 < prev    next >
Encoding:
Text File  |  1992-07-31  |  1.3 KB  |  44 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!wupost!darwin.sura.net!convex!constellation!munnari.oz.au!metro!mama!andy
  3. From: andy@research.canon.oz.au (Andy Newman)
  4. Subject: Re: Variable length records
  5. Message-ID: <Bs6GH9.AxF@research.canon.oz.au>
  6. Sender: news@research.canon.oz.au
  7. Organization: Canon Information Systems Research Australia
  8. References: <24137@castle.ed.ac.uk> <rbjmzg-.gurgle@netcom.com> <1992Jul25.091702.15993@klaava.Helsinki.FI>
  9. Date: Thu, 30 Jul 1992 01:07:56 GMT
  10. Lines: 32
  11.  
  12. wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
  13. >My gcc 2.2.2 under Linux doesn't seem to support it, at least with the
  14. >default options:
  15.  
  16. GCC uses 0 length arrays for this... from the manual...
  17.  
  18. Arrays of Length Zero
  19. =====================
  20.  
  21.    Zero-length arrays are allowed in GNU C.  They are very useful as
  22. the last element of a structure which is really a header for a
  23. variable-length object:
  24.  
  25.      struct line {
  26.        int length;
  27.        char contents[0];
  28.      };
  29.  
  30.      {
  31.        struct line *thisline = (struct line *)
  32.          malloc (sizeof (struct line) + this_length);
  33.        thisline->length = this_length;
  34.      }
  35.  
  36.    In standard C, you would have to give `contents' a length of 1,
  37. which means either you waste space or complicate the argument to
  38. `malloc'.
  39.  
  40.  
  41.  
  42. -- 
  43. Andy Newman (andy@research.canon.oz.au)        "Int. God's own type"
  44.