From owner-freebsd-hackers Thu Mar 29 22:48: 2 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from shell17.ba.best.com (shell17.ba.best.com [206.184.139.149]) by hub.freebsd.org (Postfix) with ESMTP id A7D4637B71A for ; Thu, 29 Mar 2001 22:48:00 -0800 (PST) (envelope-from toddpw@shell17.ba.best.com) Received: (from toddpw@localhost) by shell17.ba.best.com (8.9.3/8.9.2/best.sh) id WAA25263; Thu, 29 Mar 2001 22:47:55 -0800 (PST) From: Todd Whitesel Message-Id: <200103300647.WAA25263@shell17.ba.best.com> Subject: Re: Question regarding the array of size 0. In-Reply-To: <3AB87A5A.69562D89@elischer.org> from Julian Elischer at "Mar 21, 1 01:54:34 am" To: julian@elischer.org (Julian Elischer) Date: Thu, 29 Mar 2001 22:47:55 -0800 (PST) Cc: seebs@plethora.net, tech-kern@netbsd.org, freebsd-hackers@freebsd.org X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> >Can someone pls tell me if it is possible to define an array of size 0. >> >> Not in C. > >GCC and most other compilers support it. >I do it all the time (see all the various netgraph structures) however it must >be the LAST item in the structure. It gives the address of the first byte >AFTER the structure. This is very useful if the structure is a header of some >sort. While I prefer the 0-element method too, the ANSI standard doesn't allow it. Fortunately there is a portable way to get the same effect. Just put a 1-element array at the end of your header struct, and account for it when you work out how much extra space to allocate. C memory layout rules guarantee that this usage will have the desired effect. Todd Whitesel toddpw @ best.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message