Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site wjh12.UUCP
Path: utzoo!linus!vaxine!wjh12!kendall
From: kendall@wjh12.UUCP (Sam Kendall)
Newsgroups: net.lang.c
Subject: Variable-length string at end of structure
Message-ID: <483@wjh12.UUCP>
Date: Mon, 18-Jun-84 18:17:11 EDT
Article-I.D.: wjh12.483
Posted: Mon Jun 18 18:17:11 1984
Date-Received: Wed, 20-Jun-84 00:32:40 EDT
Organization: Delft Consulting Corp., New York
Lines: 25

I am wondering how many programs use the following construct, or
something similar:

	struct a {
		...
		char varlen_string[1];
	} a_struct;
	...
	p = (struct a *) malloc(sizeof (struct a) + strlen(a_string));
	... /* fill in structure members */
	(void) strcpy(p->varlen_string, a_string);

That is, malloc'ing space for a fixed-length structure plus a
variable-length string, and referencing the string using the last member
of the structure.

The Rand Editor and its derivatives do this, and Martin Minow's cpp does
it; has anyone seen other programs that do?  I'd be interested to know
how many programs do this, and exactly what type the last member of the
structure is (i.e.  is it char [1]?  char?  Something else?) I need to
know in order to put some kludge in our runtime checker to handle it;
currently it is flagged as an error.

	Sam Kendall	{allegra,ihnp4,ima,amd70}!wjh12!kendall
	Delft Consulting Corp.	    decvax!genrad!wjh12!kendall