[comp.lang.c] SUMMARY: Indefinite-length array as member of struct: how?

charles@c3pe.UUCP (Charles Green) (08/22/89)

Well, replies stopped trickling in a few (?) weeks ago, and I finally found the
time to post a summary, so here it is:

25 people replied to my posting.  Fourteen said the "correct" thing is (char*)
to a separate string in my structure rather than a char[] array; a couple of
people explained that they aren't the same thing (which I already knew, but
thanks anyway).  The reason I'd considered and discarded this approach was the
overhead of carrying around an extra (char*) [space] and two malloc() calls
rather than one [time], although two of these 14 people pointed out that I
could at least allocate the required space with a single malloc() call and set
the (char*) to point just beyond my structure to the string data space, which I
hadn't thought of.

Nine people said I should declare char[1], which is ultimately what I wound up
doing.  In the case of "K&R" (null-terminated) strings, this actually makes the
malloc() size calculation easier, as it "automagically" takes care of the
terminating null.  Three of the 9 folks who recommended the char[1] solution
pointed out that the GNU C compiler *does* allow char[0] declarations for the
very purpose I was trying to use it{, for}.

And two people mentioned "counted" strings/arrays (a la Whitesmiths C?)...

Thanks again,		Charles Green
-- 
{decuac.dec.com,cucstud,sundc}!c3pe!charles	ex::!echo Boo: