views:

43

answers:

1

I just tried the following in vala, and the assertion fails.

int[] x = {1,2};
int[] y = {1,2};
assert( x == y );

I suppose Vala compares the memory locations of x and y instead of the content of the arrays. Is there an easy way to compare two arrays without having to loop though them in vala?

+2  A: 

The generated C code indeed compare array pointers:

g_assert (x == y);

struct are being deeply compared, because they are considered "value" type. An array is a sort of "reference" type, it is not being deeply copied when you do assignement or function call (it is not on the stack).

Indeed, you'll have to loop over the elements.

Support for comparing arrays and collections might be worth adding in Gee

elmarco