Created
April 19, 2018 16:13
-
-
Save data-panda/88fd918441414110be3be1f31c26100b to your computer and use it in GitHub Desktop.
Tripple_Pointer_Legacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef double lr; | |
lr ***lr_3D_matrix(int m, int n, int o)/** \brief create a 3D matrix with size [m, n,o] of type lr*/ | |
{ | |
lr ***matrix; | |
int i, j; | |
matrix = malloc(m * sizeof(lr **)); //allocate first dimension | |
matrix[0] = malloc(m * n * sizeof(lr *)); //allocate continous memory block for all elements | |
matrix[0][0] = malloc(m * n * o * sizeof(lr)); //allocate memory for the whole matrix | |
// interleaving of pointers to make matrix[i][j][k] a valid 3d indexable array | |
for(j = 1; j < n; j++) //fill first row | |
{ | |
matrix[0][j] = matrix[0][j - 1] + o; //pointer to matrix[0][j][0], thus first element of matrix[0][j][o] | |
} | |
for(i = 1; i < m; ++i) | |
{ | |
matrix[i] = matrix[i - 1] + n; //pointer to position of to matrix[i][0] | |
matrix[i][0] = matrix[i - 1][n - 1] + o; //pointer to matrix[i][j][0]; | |
for(j = 1; j < n; ++j) | |
{ | |
matrix[i][j] = matrix[i][j - 1] + o; | |
} | |
} | |
return matrix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment