“电势除以零”是什么意思? Visual C 中的意思是++ C4723 警告描述?

发布于 2024-12-08 10:57:48 字数 549 浏览 1 评论 0原文

当我在 Visual C++ 10 中编译以下代码时,

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    int len = strlen( "" );
    if( len / 0 ) {
        rand();
    }
}

编译器发出 C4723 警告 潜在除以零

这里的潜力是什么意思?我的 C++ 代码明确表示“将 len 除以零”,除法的潜力如何?

http://msdn.microsoft.com/en-us/library/8kd039eh.aspx

When I compile the following code in Visual C++ 10

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    int len = strlen( "" );
    if( len / 0 ) {
        rand();
    }
}

the compiler emits C4723 warning potential divide by zero.

What does potential mean here? My C++ code clearly says "divide len by zero", how is the divide potential?

http://msdn.microsoft.com/en-us/library/8kd039eh.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

世俗缘 2024-12-15 10:57:48

MSDN 文章清楚地表明,编译器在编译时已将操作数评估为零。所以这里的潜在意味着编译器只不确定一件事——这段代码是否会被执行。

MSDN article is clear that compiler evaluated operand to be zero already at compile time. So potential here means that compiler is unsure about one thing only - whether this code is going to be ever executed or not.

孤城病女 2024-12-15 10:57:48

意思是一样的,只是出于礼貌。
你想让它说“你正在除以零吗,白痴!” ? (-`

It means the same, it's just been polite.
Would you like it to say "You are dividing by zero, idiot !" ? (-`

蓝眼泪 2024-12-15 10:57:48

编译器不会假设执行路径会到达被 0 除的位置。
这是一个合理的假设,因为 _tmain 的执行是在编译之后决定的。

The compiler doesn't assume the execution path will reach the division by 0.
It's a reasonable assumption, because execution of _tmain is decided after the compilation.

几度春秋 2024-12-15 10:57:48

假设您是编译器开发人员,并且您创建了一个要在编译期间运行的静态分析工具,以帮助捕获错误。

例如,这里是一个基于范围的引擎,它将确定 / 右侧运算符可能采用的可能值。

现在有两种情况:

  • 右边肯定为0
  • 右边可能为0

显然,区分这两种情况需要更多的努力。

因此,您可能会正确地假设最常见的错误原因是可能性,而不是确定性(正常人的 nodoby 会除以 0,对吗?)为自己节省一些工作。

  • 这是最佳的吗?对于开发人员来说也许,对于用户来说则不然。

  • 可以用吗?当然可以。

Say you are a compiler developer and you create a static analysis tool to be run during the compilation to help catch errors.

For example, here, a range-based engine that will determine the possible values that the right-hand operator of / could take.

Now there are two cases:

  • the right-hand side is definitely 0
  • the right-hand side is possibly 0

Obviously, separating the two cases requires more effort.

And thus you might rightly assume that the most common cause of errors will be a possibility and not a certainty (nodoby in its right mind would divide by 0, right ?) and save yourself some work.

  • Is it optimal ? For the developer perhaps, for the user not really.

  • Is it usable ? Definitely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文