I get some strange warnings about this code:
typedef double mat4[4][4]; void mprod4(mat4 r, const mat4 a, const mat4 b) { /* yes, function is empty */ } int main() { mat4 mr, ma, mb; mprod4(mr, ma, mb); }
gcc output as follows:
$ gcc -o test test.c test.c: In function 'main': test.c:13: warning: passing argument 2 of 'mprod4' from incompatible pointer type test.c:4: note: expected 'const double (*)[4]' but argument is of type 'double (*)[4]' test.c:13: warning: passing argument 3 of 'mprod4' from incompatible pointer type test.c:4: note: expected 'const double (*)[4]' but argument is of type 'double (*)[4]'
If I define the function as:
void mprod4(mat4 r, mat4 a, mat4 b) { }
Or defining matrices mainly like:
mat4 mr; const mat4 ma; const mat4 mb;
Or call the main function as follows:
mprod4(mr, (const double(*)[4])ma, (const double(*)[4])mb);
Or even define mat4 as:
typedef double mat4[16];
Gets a warning. What's going on here? Am I doing something invalid?
The gcc version is 4.4.3 if necessary.
I also posted on gcc bugzilla: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47143
My current workaround is making ugly macros that throw things for me:
#ifndef _NO_UGLY_MATRIX_MACROS #define mprod4(r, a, b) mprod4(r, (const double(*)[4])a, (const double(*)[4])b) #endif
Reply from Joseph S. Myers on gcc bugzilla:
Not a mistake. The parameters of the function are of type "pointer to an array [4] of const double", because const on the array type is applied to the element type, recursively, and then the outermost type of the array, only the type parameter splits into a pointer and the arguments passed to the type pointer to array [4] of double "after the matrix decays into a pointer, and the only case when qualifiers are allowed to be added to a task, passing arguments, etc. are qualifiers for the immediate purpose of the pointer, not nested deeper.
This sounds pretty confusing to me as a function expects:
pointer to array[4] of const doubles
and we pass
pointer to const array[4] of doubles
Intead
Or will it be the opposite? Warnings suggest that the function expects:
const double (*)[4]
which seems to me more like
pointer to const array[4] of doubles
I am really confused by this answer. Can anyone who understands what he said clarifies and illustrates?