Annoying error

This is a discussion on Annoying error within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    24

    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

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Can you post your code?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    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};

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    24
    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

  5. #5
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The code you posted doesn't match the warning message.
    Show the location of the warning.
    Kurt

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    24
    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

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Last edited by quzah; 11-09-2005 at 04:08 AM.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    24
    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

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    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?
    Sent from my iPadŽ

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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:
    Code:
    int x, y;
    y = x;
    At any rate, non-static, local variables are not initialized. The standard doesn't require it. Globals and static variables are initialized however.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21