[computer-go] C++ parameter passing

Weston Markham weston.markham at gmail.com
Wed Aug 9 14:31:30 PDT 2006


There are actually two problems here.  First, to address your
question:  "void foo(int array[])" means the same thing as "void
foo(int * const array)", where the pointer value passed references the
first element of the array.  So, passing an array by reference is
redundant.

However, the following still will not work:

void remove_from_zobrist_hash(BoardState & state, color_t color, const
uint64_t zobrist_numbers[][])

In this case, the compiler is unable to determine the total size of,
e.g., zobrist_numbers[0].  (...which is an array of const uint64_t, of
unspecified size.)  Therefore, it is unable to determine where
zobrist_numbers[1] should be located in memory.  (It immediately
follows the first element.)  You will need to specify a "complete"
type for the array elements, which basically means that only the
innermost pair of square brackets may have the size unspecified.
Something like:

void remove_from_zobrist_hash(BoardState & state, color_t color, const
uint64_t zobrist_numbers[][10])

...should work.  As will:

void remove_from_zobrist_hash(BoardState & state, color_t color, const
uint64_t zobrist_numbers[])

...which assumes that the array is flattened into a single dimension.
It is usually safe to cast a two-dimensional array to a
one-dimensional array, (occupying the same memory) as long as you
correctly figure out what the offsets of the elements are within it.

Weston

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?
>
>
> Peter Drake
> Assistant Professor of Computer Science
> Lewis & Clark College
> http://www.lclark.edu/~drake/
>
>
>
>
>
> _______________________________________________
> computer-go mailing list
> computer-go at computer-go.org
> http://www.computer-go.org/mailman/listinfo/computer-go/
>
>


More information about the computer-go mailing list