Variable-length string at end of structure
John Bruner
jdb at mordor.UUCP
Sun Jun 24 06:24:41 AEST 1984
I've used this trick in a number of programs, usually for symbol
tables and the like. The last element of my structures is
always a one-element character array.
Several years ago, when I was first maintaining APL\11 at Purdue/EE,
I had to transport it from V6 PDP-11's running the photo7 C
compiler to a VAX running 32/V. The program had compiled without
a hitch on Ritchie's compiler, but the pcc-derived VAX compiler
produced roughly 800 error messages. One of them related to the
"item" structure that APL was using. The structure was defined as:
struct item
{
char rank;
char type;
int size;
int index;
data *datap;
int dim[0];
};
(This structure appears at the beginning of each data item. Space is
allocated for the structure, "rank" elements of the array "dim", and
"size" double-precision floating-point numbers which specify the data.)
Ritchie's compiler accepted this (and perhaps still does today), but
"pcc" complained about the zero-element array "dim". I had to recode
it so that "dim" was declared with a non-zero number of dimensions
and then fudge the allocation so that the same amount of space was
allocated.
--
John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
MILNET: jdb at mordor.ARPA [jdb at s1-c] (415) 422-0758
UUCP: ...!ucbvax!dual!mordor!jdb ...!decvax!decwrl!mordor!jdb
--
John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
MILNET: jdb at mordor.ARPA [jdb at s1-c] (415) 422-0758
UUCP: ...!ucbvax!dual!mordor!jdb ...!decvax!decwrl!mordor!jdb
More information about the Comp.lang.c
mailing list