Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected ‘struct matrix_t *’ but argument is of type ‘struct matrix_t *’ ?_? no difference

main.c:78:25: erreur: assignment from incompatible pointer type [-Werror]
main.c:81:9: erreur: passing argument 2 of ‘matrix_multiply’ from incompatible pointer type [-Werror]
main.c:6:11: note: expected ‘struct matrix_t *’ but argument is of type ‘struct matrix_t *’

line 6 is the matrix_multiply function

here is my code which begin at line 74

matrix_t *m;
matrix_t *first = matrix_reader_next(reader);
matrix_t *previous = first;
while ( (m = matrix_reader_next(reader))) {
    previous->next = m;
    previous = m;
}
matrix_t *result = matrix_multiply(first,first->next);

and here are my function prototypes and structure

typedef struct {
   int **M;
   int nLi;
   int nCo;
   struct matrix_t *next;
} matrix_t;

matrix_t* matrix_multiply(matrix_t* first, matrix_t*second);
matrix_t* matrix_reader_next(matrix_reader_t *r);

I really don't understand these error message. Please help me :)

like image 781
yakoudbz Avatar asked Dec 04 '22 04:12

yakoudbz


2 Answers

Your type definition should read

typedef struct matrix_t {
   int **M;
   int nLi;
   int nCo;
   struct matrix_t *next;
} matrix_t;

Otherwise, the type matrix_t refers to a complete but unnamed structure type, whereas struct matrix_t refers to a different, named but incomplete structure type which you never define.

like image 193
Christoph Avatar answered Feb 06 '23 06:02

Christoph


Change your struct definition to this:

typedef struct matrix_t {
   int **M;
   int nLi;
   int nCo;
   struct matrix_t *next;
} matrix_t;

Notice the difference?

struct matrix_t is not the same as typedef ... matrix_t; they exist in different namespaces; so in your version of the code, the compiler assumes that struct matrix_t *next refers to a different, incomplete type.

like image 41
Oliver Charlesworth Avatar answered Feb 06 '23 05:02

Oliver Charlesworth