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

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


当前回答

这是我的两分钱。在c++中:

int* t = new int(15);
delete t;

其他回答

ruby中的隐含变量\constants和可变常量

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++中:

int* t = new int(15);
delete t;

C和c++中的三联体。

int main() {
   printf("LOL??!");
}

这将打印LOL|,因为trigraph ??!转换为|。

腮腺炎。WTF有很多特性,我选了一个if语句。(请注意,我在下面使用了一种相当冗长的编码风格,以适应那些不懂这门语言的人;真正的腮腺炎代码通常对外行来说更难以理解。)

if x>10 do myTag(x)    ; in MUMPS "tag" means procedure/function
else  do otherTag(x)

这类似于Java中的说法:

if (x > 10) {
  myMethod(x);
} else {
  otherMethod(x);
}

除了在MUMPS中,else语句在语法上不是if块的一部分,它是一个单独的语句,通过检查内置变量$TEST来工作。每次执行if语句时,它都会将$TEST设置为if语句的结果。else语句实际上意味着“如果$TEST为假,则执行该行剩余部分,否则跳转到下一行”。

这意味着如果x大于10,因此第一行叫做myTag,并且myTag包含if语句,那么else的行为不取决于它上面一行的if,而是取决于myTag内部的最后一个if !由于这个“特征”,MUMPS编码员通常被教导像这样编写以上代码以确保安全:

if x>10 do myTag(x) if 1
else  do otherTag(x)

第一行末尾的if 1确保在控制进行到下一行之前正确地设置了$TEST。(顺便说一下,这里的间距必须是这样的,在else后面有两个空格,在所有其他地方都有一个空格。间距是奇怪的,但至少一旦你理解了模式,它是非常正交的。)