I have a sourcecode like:
typedef int tQ32_16; typedef tQ32_16 tVector3[3];
tQ32_16 Length_V3(const tVector3 * vec) {....;}
void anyfunc(void) {
tVector3 v1 = {1,2,3}; tQ32_16 l1;
l1 = Length_V3(&v1); //==>> warning: #167-D: argument of type "tVector3 *" is incompatible with parameter of type "const tVector3 *"
.... }
Why do I get this warning ?? As far as I know this is correct C-code....
Besides this has nothing to do with the original problem..... this is ALSO an unjust warning !!
Look at the code !: v1 IS an array, and the parameter IS a POINTER to array !!! so &v1 is a 100% correct syntax.
And as the warning itself states: "Of the two only &a may be assigned to p without complaint" so why is it complaining ?
this is ALSO an unjust warning !!
Hmmm. You might get some disagreement on that one.
But anyway:
The reason I showed you this is precisely because it does not show anything concerning your original problem; and nor do a couple of other compilers I tried. So it suggests that maybe Keil is either being over-zealous or (horror of horrors) is wrong.
Maybe someone who obviously sees what is wrong and chooses not to say should actually back up their statement.
I think I got it. What you really want to write is the following:
typedef int tQ32_16; typedef tQ32_16 tVector3[3]; tQ32_16 Length_V3(const tVector3 vec) { tQ32_16 result = vec[0]; return result; } int main(void) { tVector3 v1 = {1,2,3}; tQ32_16 l1; l1 = Length_V3(v1); return l1; }
The type tVector3 is an array. Arrays are passed to function by reference. So in essense the type of the argument is now const int* vec. In your original code it was const int** vec which doesn't make much sense.
Mike, Thanks.
Sorry for my very limited C skill. Just want to know if my understanding is correct or not.
#include <stdio.h> int Length_V3( int vec[][3] ) { int result = vec[0][0]; return result; } int main(void) { int v1[1][3] = { { 0xA, 0xB, 0xC } }; int l1; l1 = Length_V3(&v1[0]); printf( "l1 = %X", l1 ); return 0; }
Tested with X86/WinXP/Code::Blocks 10.05
Compiling: C:\WINDOWS\Temp\main_b.c Linking console executable: C:\WINDOWS\Temp\main_b.exe Process terminated with status 0 (0 minutes, 0 seconds) 0 errors, 0 warnings
l1 = A Process returned 0 (0x0) execution time : 0.016 s Press any key to continue.