Article View: comp.std.c
Article #2906Struct hack one last time
From: M. J. Saltzman
Date: Thu, 24 Dec 1992 00:24
Date: Thu, 24 Dec 1992 00:24
34 lines
1060 bytes
1060 bytes
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
Technical Details
Message-ID:
<1992Dec24.002438.23334@hubcap.clemson.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!hubcap!mjsShow Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!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