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 (one last time)
- Message-ID: <1992Dec31.153931.7495@hubcap.clemson.edu>
- Organization: Clemson University, Clemson SC
- Date: Thu, 31 Dec 1992 15:39:31 GMT
- Lines: 27
-
- In a previous article (now expired at my site), I asked if the
- notorious "struct hack" was still conformant if the tail array in the
- struct was of type other than char. Since no-one ever replied, I'll
- ask one more time.
-
- My reading of the earlier thread on this topic was that the hack was
- indeed legal, but all the previous examples used an array of char in
- their examples. Thus, is there any reason it would not be legal to
- declare:
-
- struct vector {
- int size;
- double v[1];
- } *vec;
-
- and then code (for example):
-
- vec = malloc(sizeof(struct vector) + (n - 1) * sizeof(double));
- vec->size = n;
-
- for ( i = 0; i < vec->size; i++ ) vec->v[i] = 0.0;
-
- Thanks again for your time and assistance.
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-