Article View: comp.std.c
Article #4237Variable length struct hack
From: Denizen of the Deep
Date: Wed, 18 Oct 1995 17:45
Date: Wed, 18 Oct 1995 17:45
28 lines
1121 bytes
1121 bytes
In reference to the practise of declaring a struct as:
struct blah {
int num;
char data[1];
};
From the FAQ 9.7:
To be on the safe side, it may be preferable to declare the
variable-size element very large, rather than very small; in the case
of the above example:
...
char name[MAXSIZE];
...
where MAXSIZE is larger than any name which will be stored. (The trick
so modified is said to be in conformance with the Standard.)
I seem to remember hearing recently that even this modification is
not actually in conformance with the Standard, but I can't remember
why. Can anyone enlighten me?
If it isn't, is there any way at all to portably achieve the desired
behavior (i.e. all the data in one contiguous block)?
-Jon
Technical Details
Message-ID:
<463egk$jbb@nntp.Stanford.EDU>Path:
arc1-ca.pugleaf.net!Xenon.Stanford.EDU!beckerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!Xenon.Stanford.EDU!becker From: becker@Xenon.Stanford.EDU (Denizen of the Deep) Newsgroups: comp.std.c Subject: Variable length struct hack Date: 18 Oct 1995 17:45:56 GMT Organization: Computer Science Department, Stanford University. Message-ID: <463egk$jbb@nntp.Stanford.EDU> NNTP-Posting-Host: xenon.stanford.edu