Mail Archives: djgpp/2001/04/25/11:30:07
Cesar Rabak <csrabak AT uol DOT com DOT br> 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.
- Raw text -