The expected 'struct matrix_t *, but the 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 that starts 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 prototypes and the structure of my function

 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 this error message. Please help me:)

+4
source share
3 answers

Your type definition should read

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

Otherwise, the matrix_t type refers to a full but unnamed structure type, while struct matrix_t refers to a different but not complete structure type that you never define.

+6
source

Change the definition of struct to the following:

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

Pay attention to the difference?

struct matrix_t does not match typedef ... matrix_t ; they exist in different namespaces; therefore, in your version of the code, the compiler assumes that the struct matrix_t *next is of a different, incomplete type.

+7
source

Yeah, you don't have a struct matrix_t , but the next field is declared using the struct tag. This causes problems when using the next field.

matrix_t can be either a struct tag or a type name, since they are in different namespaces, but be that as it may, your definition starts with ...

 struct { 

not...

 struct matrix_t { 

In other words, you have an unnamed structure that has a typedef called matrix_t , but you never define struct matrix_t.

+3
source

Source: https://habr.com/ru/post/1403170/


All Articles