-
Annoying error
Hi -
I've created two matrices i.e
Code:
float matrixA[3][3];
float matrixB[3][3];
I've then done some calculations to set the values in these matrices. This goes by without any errors.
I then try and do some further calculations and set the results to a float, and then when I try to build this I get the error:
warning C4700: local variable 'matrixA' used without having been initialized
warning C4700: local variable 'matrixB' used without having been initialized
any ideas why this is happeneing?
any help is much appreciated
H
x
-
-
you will get that warning if you try to use the array before assigning any values to it. For example, VC++ 6.0 compiler produces that error
Code:
int main()
{
float matrixA[3][3];
float matrixB[3][3];
printf("%f\n", matrixA[0][0]); <<< warning here
return 0;
}
changing it like this will remove the warning because the array is initialized to all 0s.
Code:
float matrixA[3][3] = {0};
-
The thing is I have assigned values to it.
Here's the actual code that I have created:
Code:
float betaDet[3][3];
float A[3][3];
betaDet[0][0]=triangle->p0.x-ray->origin.x;
betaDet[1][0]=triangle->p0.y-ray->origin.y;
betaDet[2][0]=triangle->p0.z-ray->origin.z;
betaDet[0][1]=triangle->p0.x-triangle->p2.x;
betaDet[1][1]=triangle->p0.y-triangle->p2.y;
betaDet[2][1]=triangle->p0.z-triangle->p2.z;
betaDet[0][2]=ray->direction.x;
betaDet[1][2]=ray->direction.y;
betaDet[2][2]=ray->direction.z;
A[0][0]=triangle->p0.x-triangle->p1.x;
A[1][0]=triangle->p0.y-triangle->p1.y;
A[2][0]=triangle->p0.z-triangle->p1.z;
A[0][1]=triangle->p0.x-triangle->p2.x;
A[1][1]=triangle->p0.y-triangle->p2.y;
A[2][1]=triangle->p0.z-triangle->p2.z;
A[0][2]=ray->direction.x;
A[1][2]=ray->direction.y;
A[2][2]=ray->direction.z;
point->beta=(betaDet[0][0]*(betaDet[1][1]*betaDet[2][2]-betaDet[2][1]*betaDet[1][2])
+betaDet[0][1]*(betaDet[1][2]*betaDet[3][0]-betaDet[2][2]*betaDet[1][0])
+betaDet[0][2]*(betaDet[2][0]*betaDet[2][1]-betaDet[2][0]*betaDet[1][1]))/
(A[0][0]*(A[1][1]*A[2][2]-A[2][1]*A[1][2])
+A[0][1]*(A[1][2]*A[3][0]-A[2][2]*A[1][0])
+A[0][2]*(A[2][0]*A[2][1]-A[2][0]*A[1][1]));
Thanks for help so far,
H
x
-
The code you posted doesn't match the warning message.
Show the location of the warning.
Kurt
-
Sorry - i changed the warning messages to fit my example previously. so the warning messages now are:
warning C4700: local variable 'betaDet' used without having been initialized
warning C4700: local variable 'A' used without having been initialized
cheers,
H
-
If you can't figure out how to fix that yourself, you should give up now. Look, it's real simple:
Code:
int x;
printf( "x is %d", x ); /* <--- using x without ever initializing it */
Quzah.
-
I had initialized the values - I've just looked and the problem I had was I'd referenced matrix[3][0] which doesnt exist.
thanks anyways
H
-
I've never seen an error like that Quzah. I mean, that's what I would think the error meant by it's syntax, but then wouldn't most compilers either automatically initialize to 0 or just print out whatever garbage was in it?
-
They're not required to. It would just print whatever garbate was in it. Although it's technically not an error, it's a warning. It's just letting you know that you probably didn't mean to do that, and should fix it by actually using the variable before you do something stupid with it.
Actually, that was a poor example, because it was just a quick illustration of it being used without ever initializing it. It being used in a function call like that probably wouldn't generate the warning. (I didn't bother compiling it.) A better example would be:At any rate, non-static, local variables are not initialized. The standard doesn't require it. Globals and static variables are initialized however.
Quzah.