home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!gatech!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Subject: Struct hack one last time
- Message-ID: <1992Dec24.002438.23334@hubcap.clemson.edu>
- Summary: ...with types other than char
- Organization: Clemson University, Clemson SC
- Date: Thu, 24 Dec 1992 00:24:38 GMT
- Lines: 34
-
- I'm sorry if I'm beating a dead horse, but in all the discussion of the
- infamous "struct hack", was it ever resolved if it was legal if the
- truncated array had type other than char?
-
- E.g.
-
- struct vector {
- int length;
- double value[1];
- } *v;
-
- ...
-
- v = malloc(sizeof(struct vector) + (n - 1) * sizeof(double));
- /* ignore possible malloc failure at my own peril 8^) */
-
- v->length = n;
-
- for ( i = 0; i < v->length; i++ )
- v->value[i] = 0.0;
-
- ...
-
- I can't think of a reason why it shouldn't be, but...
-
- If not legal, what was the reasoning, and is there a way around the problem?
-
- Thanks very much.
-
-
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-