Date: Fri, 30 Mar 2001 10:21:58 -0600 (CST) From: John Gregor <johng@vieo.com> To: freebsd-hackers@FreeBSD.ORG, tech-kern@netbsd.org Subject: Re: Question regarding the array of size 0. Message-ID: <200103301621.f2UGLwY45837@vieo.com> In-Reply-To: <3AC4AE65.8C4D9482@theseventhson.freeserve.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
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[]
#endif
struct foo {
int count;
short flags;
char ARRAYSTUB(data);
};
-JohnG
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103301621.f2UGLwY45837>
