You cannot cast that static array to be a dynamic array. These types are simply not compatible. The static array is laid out in one contiguous block of memory. The dynamic array has indirection to variable sized arrays at each dimension. In effect think of it as ^^Byte
with extra compiler management and meta data. No amount of casting can help you.
You have, at least, the following options:
- Copy the contents of the static array to a dynamic array. Then pass that dynamic array to your function.
- Switch your static array to be a dynamic array so that no conversion is needed.
- Arrange that your function accepts static arrays rather than dynamic arrays, again to avoid requiring a conversion.
- Have the function accept a pointer to the first element and the inner dimension. Then perform the indexing manually. The
i,j
element is at linear offset i*innerDim + j
.
Your pointer type PMatrix
is probably not needed. Dynamic arrays are already implemented as pointers. This seems to be a level of indirection too far.
Of course, asking for element 3 when the array indices only go up to 2 isn't right, but that is presently the lesser of your concerns. Remember that dynamic arrays are zero based and you have specified zero based for your static array.
I am struggling to be able to recommend which solution is best since I don't understand your real goals and usage based on the simplified example presented here.