如何忽略MSVC中未初始化的变量错误 [英] How to ignore uninitialized variable error in MSVC

查看:40
本文介绍了如何忽略MSVC中未初始化的变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用MSVS编译器时遇到问题,我有以下代码:

I'm having problems with MSVS compiler, I have the following code:

if (!list) {
    *type = raw_data[*i++];
    ptr = (char*) &size;
    ptr[1] = raw_data[*i++];
    ptr[0] = raw_data[*i++];
    name = new char[size+1];
    memcpy (name, raw_data+*i, size);
    name[size] = '\0';
    *i += size;
}

后来:

if (!list) {
    s->name = name;
    s->name_size = size;
}

此函数中list的值不变,但是由于此错误,我无法编译代码:

The value of list doesn't change in this function, however I can't compile the code because of this error:

错误1错误C4703:可能未初始化的本地指针变量使用了名称"

Error 1 error C4703: potentially uninitialized local pointer variable 'name' used

我发现这不是一个警告,而是一个错误,真是令人讨厌.将bool更改为const bool也无济于事.有人知道如何在Visual Studio中忽略此特定错误,但仍然显示其他错误/警告吗?

I find it incredibly annoying that this isn't a warning but an error. Changing the bool to const bool doesn't help either. Does someone know how to ignore this specific error in Visual Studio, but still show other errors/warnings?

推荐答案

我怀疑您正在向编译器传递/sdl 选项,该选项告诉编译器对待4703(以及其他各种东西)作为错误而不是警告.

I suspect you're passing the compiler the /sdl option, which tells it to treat a 4703 (and various other things) as an error rather than a warning.

在对安全性抱有偏执的情况下,将其视为错误是有道理的-编译器无法证明您正在做的事情是安全的,因此不会让代码通过.如果您不想这样做,请关闭/sdl .

In the context of being paranoid about security it makes sense to treat this as an error - the compiler can't prove that what you're doing is safe, so it won't let the code through. If you don't want that, turn off /sdl.

这篇关于如何忽略MSVC中未初始化的变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆