Question

so I'm asked to make the following function:

int **multiplyM(int MA[][], int MB[][], int n, int m)

Which will multiply two matrices. The first one (MA) with dimensions n, n, and the second one (MB) with dimensions n, m. I have everything done with the program, but I get an error caused by the function itself, which says:

"array type has incomplete element type"

I know I can fix it by changing stuff in the function (like changing it to **MA and **MB), but the thing is, I'm not supposed to do that, because I'm supposed to make my program based on this function that was given to me.

So my question is: Is there a way to make this work WITHOUT changing the function?

Was it helpful?

Solution

The second dimension must be given for MA and MB

So,

#define SIZE_M 5 //Any constant
#define SIZE_N 6

int **multiplyM(int MA[][SIZE_M], int MB[][SIZE_N], int n, int m)
       //Fix ->           ^^^                ^^^

OTHER TIPS

You cannot pass a multidimensional array to a function as you are doing. You need to specify the size of the the second dimension (and any further dimension) when declaring the function. Specifying the size here is important. If it were not mandatory, the compiler won't be able to deal with expression such Array[2][3]. The value used as array dimension must be a constant for ANSI C an other versions, but it can be a variable for C99 and successive versions. The C99 standard introduced the variable-length arrays feature, which allows to determine the size of an array at run-time.

So:

#define N 10
#define M 5 

int **multiplyM(int MA[][N], int MB[][M], int n, int m)

I know I can fix it by changing stuff in the function (like changing it to **MA and **MB), but the thing is, I'm not supposed to do that, because I'm supposed to make my program based on this function that was given to me.

Without modifying at least the declaration of the function, you are not going to solve this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top