如何使用/ we4700编译时在本地禁用错误C4700

时间:2013-06-25 04:34:09

标签: c++ visual-c++

考虑以下代码

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;
}

任何想法,如何处理它?<​​/ p>

0 个答案:

没有答案