Constant of 2D array

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Constant of 2D array

Felipe Monteiro de Carvalho
Hello,

Can I write constants of a 2D array? I am trying to convert some C++
code which uses this ... so far I tryed:

const number_return_map: array[0..7][0..7] of U8 =
(
  ( 15, 14, 13, 12, 11, 10,  9,  8 ),
  ( 14,  0,  1,  3,  6, 10, 10,  9 ),
  ( 13,  1,  2,  4,  7, 11, 11, 10 ),
  ( 12,  3,  4,  5,  8, 12, 12, 11 ),
  ( 11,  6,  7,  8,  9, 13, 13, 12 ),
  ( 10, 10, 11, 12, 13, 14, 14, 13 ),
  (  9, 10, 11, 12, 13, 14, 15, 14 ),
  (  8,  9, 10, 11, 12, 13, 14, 15 )
);

but it stops between the two [0..7] requesting a "of", which indicates
that it does not want a 2D array but expects a 1D array only.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constant of 2D array

Vincent Snijders-3
2012/9/11 Felipe Monteiro de Carvalho <[hidden email]>:
> Hello,
>
> Can I write constants of a 2D array? I am trying to convert some C++
> code which uses this ... so far I tryed:
>
> const number_return_map: array[0..7][0..7] of U8 =

const number_return_map: array[0..7,0..7] of byte =

Vincent
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constant of 2D array

Felipe Monteiro de Carvalho
On Tue, Sep 11, 2012 at 2:58 PM, Vincent Snijders
<[hidden email]> wrote:
> const number_return_map: array[0..7,0..7] of byte =

Ah, nice, thanks =) Now it works... and the syntax is almost the same
as in C++ which facilitates the conversion

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constant of 2D array

Alexander Shishkin
In reply to this post by Felipe Monteiro de Carvalho
11.09.2012 16:51, Felipe Monteiro de Carvalho пишет:

> Hello,
>
> Can I write constants of a 2D array? I am trying to convert some C++
> code which uses this ... so far I tryed:
>
> const number_return_map: array[0..7][0..7] of U8 =
> (
>    ( 15, 14, 13, 12, 11, 10,  9,  8 ),
>    ( 14,  0,  1,  3,  6, 10, 10,  9 ),
>    ( 13,  1,  2,  4,  7, 11, 11, 10 ),
>    ( 12,  3,  4,  5,  8, 12, 12, 11 ),
>    ( 11,  6,  7,  8,  9, 13, 13, 12 ),
>    ( 10, 10, 11, 12, 13, 14, 14, 13 ),
>    (  9, 10, 11, 12, 13, 14, 15, 14 ),
>    (  8,  9, 10, 11, 12, 13, 14, 15 )
> );
>
> but it stops between the two [0..7] requesting a "of", which indicates
> that it does not want a 2D array but expects a 1D array only.
>

No "of" required by array syntax. But array may be multidimensional.
Should be const number_return_map: array[0..7] of array [0..7] of U8 ...
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal