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

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


当前回答

在C语言中,

 int x = 1;
 int y = x++ + ++x;
 printf("%d", y);

是模棱两可的,打印什么取决于编译器。编译器可以在计算++x之前或在语句的末尾存储x++的新值。

其他回答

在Ruby中…

i=true
while(i)
   i=false
   a=2
end
puts defined?(a) // returns true

在MySQL中字符串比较是不区分大小写的。

> SELECT * FROM blah WHERE foo = 'BAR';
> SELECT * FROM blah WHERE foo = 'Bar';
> SELECT * FROM blah WHERE foo = 'bAr';

都是等价的。它们不仅会匹配任何看起来像'bar'的foo值(例如,如果foo = 'bar',它将匹配bar, bar, bar等)。

回想起来,FORTRAN的计算goto是相当奇怪的。维基百科告诉我一些基础知识胜过它。

另一个著名的最爱是Algol 60的名称参数调用传递。

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.

COMEFROM是我见过的最奇怪,也可能是最没用的语言功能。

其次是三元运算符,因为它违反了优化的第一条规则。它带来的危害大于它解决的问题。它的危害更大,因为它使代码可读性更差。

并不是一个真正的语言功能,但有趣/很棒的功能使用是Duff的设备。