Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.grandecom!news.posted.grandecom.POSTED!not-for-mail NNTP-Posting-Date: Sat, 17 Dec 2011 12:06:11 -0600 User-Agent: Microsoft-Entourage/12.23.0.091001 Date: Sat, 17 Dec 2011 12:06:10 -0600 Subject: Re: Simple argument question From: Bint Newsgroups: comp.lang.c++ Message-ID: Thread-Topic: Simple argument question Thread-Index: Acy85o4ihbqClJJgYUeOTOYIDj4i0A== References: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Lines: 56 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 216.82.212.181 X-Trace: sv3-E2JTo2k2h+J/A+r4jfw7f85zueNMRwkdg7SaxnFReMViQZfrfhxrXgVj7cebN/zITtBDsUGW6iRBdS4!P0SV113vVAGN+RAup3dUyco139pW1y1lUQUpXaCAsfDaVLB02C3iUwogeNDyxxk= X-Complaints-To: abuse@grandecom.com X-DMCA-Complaints-To: abuse@grandecom.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3203 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:12623 > "Bint" wrote in message news:CB114269.B5F7%bint@ign.com... >> Hi can someone answer a simple question involving arguments to functions? >> >> I need to call a library function which expects an argument like this >> Function(double pointlist[][3]); >> >> My question is how do I make one of those if I am just wanting to malloc >> the >> memory? Can I use a double pointer? >> >> Can I have something like this: >> double *points = (double *)malloc(10*3*sizeof(double)); >> >> for int (j = 0; j < 10; j++) { >> *(points + j*3 + 0) = x; >> *(points + j*3 + 1) = y; >> *(points + j*3 + 2) = z; >> } >> >> And then call the function with points as the argument? It doesn't >> compile >> but I was wondering if I could cast it? Or do I need something else >> instead >> of a double pointer for my points? >> >> Does that make sense? I am confused about how to call the function with >> anything but something like: >> double array[500][3]; >> >> I don't want that because I don't know the number of points, see? >> > Hi. > When you create 2d arrays using new you may use pointer to pointer types , > but this is a different type from the built in array type. > In your function argument your 2d array will decay into a pointer of type: > double (*)[3] > > Each dimensional array is pointed to by a pointer of type one dimension > less. For example a one dimensional array of doubles is pointed to by a > double*( the same as a pointer to a single double ). A 2-d array is pointed > to by a type T(*)[S] . a 3d array is pointed to by a type T(*)[S1][S2] etc > etc. > > When you create your pointer with malloc you are creating a pointer of type > double* which is a pointer to a 1d array, or a pointer to a single double. > But the function argument needs you to pass a 2d array. > So how would I create and pass something valid to this function, say for an array of [10][3], but specifying that 10 at run-time? Do I use new instead of malloc? Thanks B