I'm making some functions to handle matrices. My idea was to define a structure like this:
typedef struct {
int32_t rows;
int32_t cols;
float *m;
} matrix_struct;
The pointer m should contain the address to the various element of the matrix, but since its size it's arbitrary i'll have to define an array later on.
At this point i need a function to define exactly a matrix:
void matrix_create(int rows, int cols, matrix_struct *M)
{
float matrix[rows*cols];
(M -> rows) = rows;
(M -> cols) = cols;
(M -> m) = &matrix;
}
Here's my question: is it okay to define the matrix array this way? Does the float matrix array survive after matrix_create() is executed?
And if it survives, if i create a temporary matrix to work and call the function at k-rate, will the variable be destroyed at the end of the k-rate cycle or will it fill up memory?