From owner-freebsd-hackers Sun Mar 3 9:28:26 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from damnhippie.dyndns.org (12-253-177-2.client.attbi.com [12.253.177.2]) by hub.freebsd.org (Postfix) with ESMTP id 25D1B37B432 for ; Sun, 3 Mar 2002 09:27:17 -0800 (PST) Received: from [172.22.42.2] (peace.hippie.lan [172.22.42.2]) by damnhippie.dyndns.org (8.11.6/8.11.6) with ESMTP id g23HRG852615 for ; Sun, 3 Mar 2002 10:27:16 -0700 (MST) (envelope-from freebsd@damnhippie.dyndns.org) User-Agent: Microsoft Outlook Express Macintosh Edition - 5.01 (1630) Date: Sun, 03 Mar 2002 10:27:17 -0700 Subject: Re: A few questions about a few includes From: Ian To: freebsd-hackers Message-ID: In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > In : > > /* > * pargs, used to hold a copy of the command line, if it had a sane > * length > */ > struct pargs { > u_int ar_ref; /* Reference count */ > u_int ar_length; /* Length */ > u_char ar_args[0]; /* Arguments */ > }; > > This does indeed seem to make little or no sense. Could someone explain > this? Is ar_args supposed to be a pointer or what? This is a common technique for defining a structure which is some descriptive information about an array of objects is followed by an open-ended array of those objects. (In this case the "objects" are characters.) The ar_args member of the structure gives a name to that location in the structure without reserving any space (and thus when the technique is used, there can only ever be one [0] member and it must be at the end of the structure). You access the open-ended array of objects just as you would any other array embedded within a structure, E.G. instance->ar_args[n]. Not all compilers support defining zero-length arrays like this. And that's a pity; it's an incredibly useful technique, and the alternatives to it are not nearly as elegant and generally involve ugly recasting of pointers. -- Ian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message