Subject: Re: Question regarding the array of size 0.
To: None <freebsd-hackers@FreeBSD.ORG,>
From: John Gregor <>
List: tech-kern
Date: 03/30/2001 10:21:58
Lord Isildur wrote:
> sine one knows the size of the struct, who need the pointer? just
> take the displacement.
> char* buf; /* some buffer */
> struct foo{
> int header;
> struct funkystruct blah;
> };
> (struct foo*)buf; /*your headers are here */
> (struct foo*)buf+1; /* and your data is here */

The only problem is that:

struct foo {				(struct foo*)buf;
    int count;		- and -		(struct foo*)buf+1;
    short flags;
    char data[0];

will have different alignments.  If what you want is for data[] to
begin immediately after flags, buf+1 doesn't work.

Oh, and as to the data[] vs data[0] problem, one can always do the
equivalent of:

#if defined(C99STUBS)
#	define ARRAYSTUB(x) x[0]
#elif defined(GCCSTUBS)
#	define ARRAYSTUB(x) x[]

struct foo {
    int			 count;
    short		 flags;
    char       ARRAYSTUB(data);