[fpc-pascal] Initializing dynamic arrays
Marco van de Voort
marcov at stack.nl
Mon Jun 4 15:30:03 CEST 2012
In our previous episode, Jonas Maebe said:
> > m1: Matrix = ((1, 2, 3), (2, 3, 4));
> > and get a properly sized dynamic array matching the matrix given.
> > This is obviously not supported, but what can I do? I can build an
> > infinite number of functions, taking fixed-sized arrays as input and
> > returning a dynamic array, but then I need one function for each
> > combination of height and width! That is OK for sizes up to 3 or 4 but
> > then it becomes ridiculous.
> > Is there a better way to solve this problem?
> I think this is a case where a pointer combined with a width and
> height parameter is probably the best solution. The more Pascal-like
> and cleaner approach using open array parameters is only generic if
> you limit yourself to 1-dimensional arrays.
Numlib does this, though dimensions (1 or 2) must be passed as separate
arguments, and instead of a pointer often a var variable of the cell type is
determinants, eigen values, quite some is there.
More information about the fpc-pascal