From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Dynamically Allocated Arrays in C Followup-To: poster Date: 25 Apr 2001 15:24:28 GMT Organization: Aachen University of Technology (RWTH) Lines: 24 Message-ID: <9c6q7c$h1d$1@nets3.rz.RWTH-Aachen.DE> References: <9c6b8b$3dd$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <3AE6E280 DOT 6806376D AT uol DOT com DOT br> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 988212268 17453 137.226.32.75 (25 Apr 2001 15:24:28 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 25 Apr 2001 15:24:28 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Cesar Rabak wrote: > Hans-Bernhard Broeker wrote: >> > [snipped] >> >> As this is a generic C question, it's not a big surprise that the C >> FAQ (posted regularly to comp.lang.c, among other places) has the >> answer for it --- and it even manages to get away with only two >> malloc() calls, instead of (1+firstDim) ones. Go figure. > Although you're quite right about the C-faq (question 6.16 covers this), > the technique along the lines of the OP (once cleared of the errors, it > is!) are proposed by a lot of sources, one of them the "Numerical > Recipes" book, as the access to the elements is more 'natural' and thus > the code more easy to read and by consequence more 'maintenable'. The method in the C FAQ I had in mind (the 'array2' one) does all that, and quite nicely, too. It still lets you write a[i][j] to access an element of the matrix. But if you want, you can also write (*a)[i*rowlength + j] instead. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.