Changing array representation without copy
In C you can do: int main (void) { int M[100][100] = { /*...*/ }; int * A = M; // Work with A as if it's 100*100=10000 element 1D array... } Allowing to change value M from a different view, which is probably UB. On flat memory it should work, so what are more portable alternatives in Ada? Use Unchecked_Conversion, which already implies a copy. Declare a variable with needed array type (possibly with aliased component type) and use for-clause to set its address to the target (here) matrix variable. Use access types and their conversions (seemingly the same approach as in the C snippet). Doing
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.