home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3305 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.1 KB  |  37 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!gatech!hubcap!mjs
  3. From: mjs@hubcap.clemson.edu (M. J. Saltzman)
  4. Subject: Struct hack one last time (one last time)
  5. Message-ID: <1992Dec31.153931.7495@hubcap.clemson.edu>
  6. Organization: Clemson University, Clemson SC
  7. Date: Thu, 31 Dec 1992 15:39:31 GMT
  8. Lines: 27
  9.  
  10. In a previous article (now expired at my site), I asked if the
  11. notorious "struct hack" was still conformant if the tail array in the
  12. struct was of type other than char.  Since no-one ever replied, I'll
  13. ask one more time.
  14.  
  15. My reading of the earlier thread on this topic was that the hack was
  16. indeed legal, but all the previous examples used an array of char in
  17. their examples.  Thus, is there any reason it would not be legal to 
  18. declare:
  19.  
  20.     struct vector {
  21.         int  size;
  22.         double v[1];
  23.     } *vec;
  24.  
  25. and then code (for example):
  26.  
  27.     vec = malloc(sizeof(struct vector) + (n - 1) * sizeof(double));
  28.     vec->size = n;
  29.  
  30.     for ( i = 0;  i < vec->size;  i++ )  vec->v[i] = 0.0;
  31.  
  32. Thanks again for your time and assistance.
  33. -- 
  34.         Matthew Saltzman
  35.         Clemson University Math Sciences
  36.         mjs@clemson.edu
  37.