From owner-freebsd-questions@FreeBSD.ORG Tue Jun 30 02:12:14 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4E5A7106566C for ; Tue, 30 Jun 2009 02:12:14 +0000 (UTC) (envelope-from corky1951@comcast.net) Received: from QMTA07.westchester.pa.mail.comcast.net (qmta07.westchester.pa.mail.comcast.net [76.96.62.64]) by mx1.freebsd.org (Postfix) with ESMTP id EB4798FC0C for ; Tue, 30 Jun 2009 02:12:13 +0000 (UTC) (envelope-from corky1951@comcast.net) Received: from OMTA18.westchester.pa.mail.comcast.net ([76.96.62.90]) by QMTA07.westchester.pa.mail.comcast.net with comcast id 9nnc1c0051wpRvQ572CEvo; Tue, 30 Jun 2009 02:12:14 +0000 Received: from comcast.net ([98.203.142.76]) by OMTA18.westchester.pa.mail.comcast.net with comcast id A2D21c00Z1f6R9u3e2D3uG; Tue, 30 Jun 2009 02:13:04 +0000 Received: by comcast.net (sSMTP sendmail emulation); Mon, 29 Jun 2009 19:12:11 -0700 Date: Mon, 29 Jun 2009 19:12:10 -0700 From: Charlie Kester To: freebsd-questions@freebsd.org Message-ID: <20090630021210.GA72216@comcast.net> Mail-Followup-To: freebsd-questions@freebsd.org References: <19017.24376.343126.389436@jerusalem.litteratus.org> <4.3.2.7.2.20090629204828.02ee3cb8@mail.pchotshots.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <4.3.2.7.2.20090629204828.02ee3cb8@mail.pchotshots.com> X-Mailer: Mutt 1.5.20 X-Composer: VIM 7.2 User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: OT: C syntax question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2009 02:12:14 -0000 On Mon 29 Jun 2009 at 17:51:37 PDT Brad Mettee wrote: > >I believe since you are declaring the array as having a fixed number >of elements, you must declare the function to take it the same way, >like this: > > extern int plate_shift(struct CONTINENT *[10][10],int,float); > >Without the 10,10 size definition, the plate_shift function would have >no idea how big the array of pointers actually is. Close. If you pass a two-dimensional array as an argument, you must specify at least the number of elements in the "minor" dimension, so the compiler will know how to compute, for example, the offset of array[3][0] versus array[6][0]. So this works: extern int plate_shift(struct CONTINENT *[][10], int, float); But the following doesn't work, because it doesn't tell the compiler how to compute the offsets: extern int plate_shift(struct CONTINENT *[10][], int, float); Of course, it doesn't hurt to specify the number of elements in both dimensions. But it would be a less general solution, With only the minor dimension specified, plate_shift can take pointers to arrays of 20, 30, 40, 100 or 200 CONTINENT structures. Any multiple of 10 will do. (But then you need to tell plate_shift when it's reached the last set of pointers, or it might run off the end of the array. The usual way to handle this is to use all NULLs in the last row, as a kind of "sentinel".)