From owner-freebsd-hackers Fri Mar 30 8:22: 3 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from vieo.com (vieo.com [216.30.79.131]) by hub.freebsd.org (Postfix) with ESMTP id 6A3C237B71C for ; Fri, 30 Mar 2001 08:21:59 -0800 (PST) (envelope-from johng@vieo.com) Received: (from johng@localhost) by vieo.com (8.11.2/8.11.2) id f2UGLwY45837; Fri, 30 Mar 2001 10:21:58 -0600 (CST) (envelope-from johng) Date: Fri, 30 Mar 2001 10:21:58 -0600 (CST) From: John Gregor Message-Id: <200103301621.f2UGLwY45837@vieo.com> To: freebsd-hackers@FreeBSD.ORG, tech-kern@netbsd.org Subject: Re: Question regarding the array of size 0. In-Reply-To: <3AC4AE65.8C4D9482@theseventhson.freeserve.co.uk> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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