[computer-go] C++ parameter passing
Lars Nilsson
chamaeleon at gmail.com
Wed Aug 9 14:38:12 PDT 2006
Assuming the dimensions of zobrist_numbers is known somewhere (int
zobrist_numbers[dim1][dim2]):
void remove_from_zobrist_hash(BoardState &state, color_t color, const
uint64_t *zobrist_numbers)
{
... x = zobrist_numbers[i*19+j] ...
}
Call like the following:
uint64_t zobrist_numbers[19][19];
remove_from_zobrist_hash(state, color, &zobrist_numbers[0][0[);
The line in the function would have been equivalent to "x =
zobrist_numbers[i][j]" if I hadn't changed the declaration to be a
const pointer to uint64_t.
Basically, it is not valid to define a function with a argument of "X
foo[][]". At the very least you need to write "X foo[][19]".
If the dimension is fixed at compile-time you could use "const
uint64_t zobrist_number[19][19]" (or whatever dimensions you happen to
work with), but I imagine you'd want to change the size at runtime
depending on the board size you wish to play on.
Lars Nilsson
On 8/9/06, Peter Drake <drake at lclark.edu> wrote:
>
> I'd like to pass a large array by constant reference. I tried this:
>
> void remove_from_zobrist_hash(BoardState & state, color_t
> color, const uint64_t & zobrist_numbers[][])
>
> The offending parameter is zobrist_numbers. The compiler says:
>
> ../BitBoard.h:158: error: declaration of 'zobrist_numbers' as array of
> references
>
> Is there another way to do this?
More information about the computer-go
mailing list