I have a function that takes two 2d matrices of variable dimensions and returns a matrix of equal dimensions.
double (*sumOfMatrices(size_t rows, size_t columns, double matrixA[][columns], double matrixB[][columns]))[] {
double (*result)[columns]= malloc(rows * sizeof *result);
for (size_t i = 0; i < rows; i++)
{
for (size_t j = 0; j < columns; j++)
{
result[i][j]= matrixA[i][j] + matrixB[i][j];
}
}
return result;
}
Then I declare a variable like this
double (*sumResult)[n]= sumOfMatrices(m, n, matrixA, matrixB);
Is this undefined behavior? The compiler doesn't say anything, yet I feel that initializing a double(*)[n] with a double(*)[] is implicitly promoting the data type. Is there a way that I can return double(*)[columns] instead?