Hi,
Does anyone know the syntax for initializing a dynamic array of more than one dimension?
type {$ifdef __GPC__} tMSet (n:CWord) = Array [1..n, 1..n] Of double; {$else} tMSet = Array Of Array Of double;
var MSet : tMSet; {$endif}
pMSet : ^tMSet;
........
{$ifdef __GPC__} new (pMset, n, n); {$else} SetLength (Mset, n, n); pMSet := @Mset; {$endif}
The above works in FPC, but fails in GPC on the "new" with "error: `New' applied to this schema requires 1 discriminant value"
This general approach works fine for 1D arrays.
Regards, Peter B
Peter B wrote:
Does anyone know the syntax for initializing a dynamic array of more than one dimension?
type {$ifdef __GPC__} tMSet (n:CWord) = Array [1..n, 1..n] Of double; {$else} tMSet = Array Of Array Of double;
var MSet : tMSet; {$endif}
pMSet : ^tMSet;
........
{$ifdef __GPC__} new (pMset, n, n); {$else} SetLength (Mset, n, n); pMSet := @Mset; {$endif}
The above works in FPC, but fails in GPC on the "new" with "error: `New' applied to this schema requires 1 discriminant value"
This general approach works fine for 1D arrays.
As the error message says, 'tSet' is a schema with _one_ parameter (discrimnant). So 'new' requires single parameter, that is 'n'. In general you may use complicated formula to compute array bounds from discriminant values. GPC generated appropriate code so that 'new' will do right thing.
On 14/02/17 15:37, Waldek Hebisch wrote:
Peter B wrote:
Does anyone know the syntax for initializing a dynamic array of more than one dimension?
type {$ifdef __GPC__} tMSet (n:CWord) = Array [1..n, 1..n] Of double; {$else} tMSet = Array Of Array Of double;
var MSet : tMSet; {$endif}
pMSet : ^tMSet;
........
{$ifdef __GPC__} new (pMset, n, n); {$else} SetLength (Mset, n, n); pMSet := @Mset; {$endif}
The above works in FPC, but fails in GPC on the "new" with "error: `New' applied to this schema requires 1 discriminant value"
This general approach works fine for 1D arrays.
As the error message says, 'tSet' is a schema with _one_ parameter (discrimnant). So 'new' requires single parameter, that is 'n'. In general you may use complicated formula to compute array bounds from discriminant values. GPC generated appropriate code so that 'new' will do right thing.
Hi Waldek,
Thanks. Doing "new (pMset, n)" did compile, but failed with a range check. I had made another mistake, having GPC ranges from '1..n' whereas the code written for FPC needs ranges fixed as '0..n-1'
Regards, Peter
On 14/02/17 13:06, Peter wrote:
Hi,
Does anyone know the syntax for initializing a dynamic array of more than one dimension?
type {$ifdef __GPC__} tMSet (n:CWord) = Array [1..n, 1..n] Of double; {$else} tMSet = Array Of Array Of double;
var MSet : tMSet; {$endif}
pMSet : ^tMSet;
........
{$ifdef __GPC__} new (pMset, n, n); {$else} SetLength (Mset, n, n); pMSet := @Mset; {$endif}
The above works in FPC, but fails in GPC on the "new" with "error: `New' applied to this schema requires 1 discriminant value"
This general approach works fine for 1D arrays.
Regards, Peter B
Gpc mailing list Gpc@gnu.de https://www.g-n-u.de/mailman/listinfo/gpc
Fixed, I think.
Changing the line tMSet (n:CWord) = Array [1..n, 1..n] Of double; to tMSet (j,k:LongInt) = Array [0..j-1, 0..k-1] Of double;
is working much better.