gpt4 book ai didi

compiler-errors - 为什么我不会在未使用的局部变量上出现编译器错误?

转载 作者:行者123 更新时间:2023-12-04 07:03:07 26 4
gpt4 key购买 nike

Dlang documentation状态:

It is an error to declare a local variable that is never referred to. Dead variables, like anachronistic dead code, are just a source of confusion for maintenance programmers.

我在 ldc 0.14gdc 5.1dmd 2.067.1 中编译了以下代码:

void main()
{
int i;
//local variable i not used...
}

我没有收到任何编译器错误。这应该编译失败吗?

最佳答案

很多这些错误的东西实际上并没有实现。它们是很好的东西,编译器作者保留犯错误的权利(根据规范,你的代码无论如何都是错误的),但实际上还没有完成......也许永远不会真正做。

It is an error to use a local variable without first assigning it a value. The implementation may not always be able to detect these cases. Other language compilers sometimes issue a warning for this, but since it is always a bug, it should be an error.

这还没有实现,而且可能永远不会实现,因为人们依赖自动初始化作为一项功能。

It is an error to declare a local variable that is never referred to. Dead variables, like anachronistic dead code, are just a source of confusion for maintenance programmers.

未实现

It is an error to return the address of or a reference to a local variable.

仅部分实现。

关于compiler-errors - 为什么我不会在未使用的局部变量上出现编译器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com