Udostępnij za pośrednictwem


C6001

warning C6001: using uninitialized memory <variable>

This warning is reported when an uninitialized local variable is used before it is assigned a value. This could lead to unpredictable results. You should always initialize variables before use.

Example

The following code generates this warning because variable i is only initialized if b is true; otherwise an uninitialized i is returned:

int f( bool b )
{
   int i;
   if ( b )
   {
      i = 0;
   }
   return i; // i is unintialized if b is false
}

To correct this warning, initialize the variable as shown in the following code:

int f( bool b )
{
   int i= -1;

   if ( b )
   {
      i = 0;
   }
   return i;
}

See Also

Reference

Compiler Warning (level 1 and level 4) C4700

Compiler Warning (level 4) C4701