在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

其他回答

在C:

warning C4013: 'myfunc' undefined; assuming extern returning int

我记得由于某些原因没有看到警告(在一些遗留代码中有太多警告?),并且困惑于为什么从int转换会在使用非int返回函数时导致编译器错误。

编译器假设这样的东西是相当出乎意料的。

Java的Integer类的基转换静态方法。P似乎很少有语言内置了这个功能。

早期的FORTRAN,空格不重要。(anti-Python !)

DO 20 I = 1, 10

含义:从这里循环到第20行,I从1到10。

DO 20 I = 1. 10

含义:将1.10分配给名为DO20I的变量。

有传言说这个漏洞毁了一个太空探测器。

JavaScript是面向对象的,对吧?因此,在文字字符串和数字上运行方法应该是可行的。比如"hello". touppercase()和3.toString()。第二个是语法错误,为什么?因为解析器期望一个数字后面跟一个点是一个浮点字面值。这不是WTF, WTF是你只需要再加一个点就可以了:

3..toString()

原因是字面上的3。被解释为3.0,3.0. tostring()工作正常。

在c++

const char* wtf()
{
    char buf[100];
    return buf;
}
string s = ... + wtf() + ...;

在s中创建有趣的值。部分是字符串,部分是堆栈内容,与零混合,因此s.length()!=strlen(s.c_str())。 最奇怪的是,编译器在返回指向堆栈的指针时完全没有问题——如果他在那里添加了一个警告,编译器程序员的手可能会掉下来。