home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3262 < prev    next >
Encoding:
Text File  |  1992-12-23  |  1016 b   |  45 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
  5. Message-ID: <1992Dec24.002438.23334@hubcap.clemson.edu>
  6. Summary: ...with types other than char
  7. Organization: Clemson University, Clemson SC
  8. Date: Thu, 24 Dec 1992 00:24:38 GMT
  9. Lines: 34
  10.  
  11. I'm sorry if I'm beating a dead horse, but in all the discussion of the 
  12. infamous "struct hack", was it ever resolved if it was legal if the 
  13. truncated array had type other than char?
  14.  
  15. E.g.
  16.  
  17.     struct vector {
  18.         int length;
  19.         double value[1];
  20.     } *v;
  21.  
  22.     ...
  23.  
  24.     v = malloc(sizeof(struct vector) + (n - 1) * sizeof(double));
  25.     /* ignore possible malloc failure at my own peril 8^) */
  26.  
  27.     v->length = n;
  28.  
  29.     for ( i = 0;  i < v->length;  i++ )
  30.         v->value[i] = 0.0;
  31.  
  32.     ...
  33.  
  34. I can't think of a reason why it shouldn't be, but...
  35.  
  36. If not legal, what was the reasoning, and is there a way around the problem?
  37.  
  38. Thanks very much.
  39.  
  40.  
  41. -- 
  42.         Matthew Saltzman
  43.         Clemson University Math Sciences
  44.         mjs@clemson.edu
  45.