考虑以下代码
int TestReadUninitStack()
{
printf("Reading an uninitialized stack variable\n");
int i;
volatile int j = i;
fprintf(stderr, "ERROR: Uninitialized stack variable read not detected!\n");
return 2;
}
当我使用/we4700编译我的项目时,这段代码因编译错误而失败
error C4700: uninitialized local variable 'i' used
为了解决编译错误,我添加了一个编译指示以暂时禁用代码块周围的C4700警告,但不幸的是,这似乎不起作用
int TestReadUninitStack()
{
printf("Reading an uninitialized stack variable\n");
#pragma warning( push )
#pragma warning( disable : 4700 )
int i;
volatile int j = i;
#pragma warning( pop )
fprintf(stderr, "ERROR: Uninitialized stack variable read not detected!\n");
return 2;
}
任何想法,如何可能处理它?