Warning C6246
Local declaration of 'variable' hides declaration of same name in outer scope. Additional Information: See previous declaration at 'location'.
Remarks
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.
Code analysis name: LOCALDECLHIDESLOCAL
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for