Expand Minimize

C6246

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.

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft