I'm creating a simple library function for basic matrix operations and one of it is matrix addition,as IMO the function seems to have too many parameters passed to it, but on the other hand i feel all the parameters passed are required and there is no other way to get them in the function directly.
so here's the code snippet :
void mat_add(int r1, int c1, int m1[][c1], int r2, int c2, int m2[][c2],int res[][c1])
{
if (r1 == r2 && c1 == c2)
{
for (int i = 0; i < r1; i++)
{
for (int j = 0; j < c1; j++)
{
res[i][j] = m1[i][j] + m2[i][j];
}
}
}
else
{
fprintf(stderr, "ERROR:matrix sizes are not same\n");
exit(-1);
}
}
Of course, its the real necessary parameters should be passed,
but I really dont know what i am doing is just too much,it can be reduced or not,
so is there any way you can reduce the number of parameters passed and get the required data(#rows and #columns) from those itself in the function?