C6246

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6246: Local declaration of <variable> hides declaration of same name in outer scope. Additional Information: See previous declaration at <location>.

This warning indicates that two declarations have the same name at local scope. The name at outer scope is hidden by the declaration at the inner scope. Any intended use of the outer scope declaration will result in the use of local declaration.

Example

The following code generates this warning:

#include <stdlib.h>  
#define UPPER_LIMIT 256  
int DoSomething( );  
  
int f( )  
{  
  int i = DoSomething( );  
  if (i > UPPER_LIMIT)  
  {  
    int i;  
    i = rand( );  
  }  
  return i;  
}  

To correct this warning, use another variable name as shown in the following code:

#include <stdlib.h>  
#define UPPER_LIMIT 256  
int DoSomething( );  
  
int f ( )  
{  
  int i = DoSomething( );  
  if (i > UPPER_LIMIT)  
  {  
    int j = rand( );  
    return j;  
  }  
  else  
  {  
    return i;  
  }  
}  

This warning only identifies a scope overlap.