void print_first_n_row(double **matrix, int n, int row_size) {
double (*abc)[row_size];
abc=matrix;}
I am having assignment from incompatible pointer type [-Wincompatible-pointer-types] abc=matrix error. How can I solve this?
A matrix is an abstract data type. How you implement it is an implementation detail.
In this answer I detailed how you could implement such a type in C.
Multi-dimensional arrays don't really exist in C. C just have arrays of arrays, or arrays of pointers -or other types, including arrays of scalars. Check by reading n1570 (the C11 standard).
I am having assignment from incompatible pointer type [-Wincompatible-pointer-types] abc=matrix error. How can I solve this?
Either think in abstract data types terms, or read more about C dynamic memory allocation (consider using flexible array members) and about the C programming language.
You'll find many examples of matrix-related source code on github or gitlab and elsewhere.
Note: This answer is just regarding the error message, not the logic behind passing pointers to a matrix.
"I am having assignment from incompatible pointer type [-Wincompatible-pointer-types] abc=matrix error. How can I solve this?"
double (*abc)[row_size]; - abc is a pointer to an array of double.
double **matrix - matrix is a pointer to a pointer to double.
There is a mismatch. * vs. **.
You can´t assign the value of a pointer to a pointer to double to a pointer to an array of double.
Change double (*abc)[row_size]; to double **abc or double (**abc)[row_size]; or just use matrix if abc isn´t needed otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With