On 2010-05-30 23:12:06 +0200, "Simen kjaeraas" <simen.kja...@gmail.com> said:
Going again with the C code:
typedef struct array {
int* data;
int length;
};
You would use an array like this:
void foo( ) {
array arr;
arr.ptr = malloc(32);
arr.length = 8;
}
Now, as you can probbly see, &arr would give the pointer to the
struct, not to the data. Basically, a pointer to pointer to int,
rather than the pointer to int you want.
Ok, I thought that the structure was a bit more flat like:
typedef struct array {
int length;
int[1..length] data;
}
Avoiding one indirection as it could be assumed that the
memory-allocator / GC will return a continous piece for the array. But
of course resizing and reallocation would be a bit more complicated.
--
Robert M. Münch
http://www.robertmuench.de