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

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


当前回答

在x++ (Microsoft Dynamics AX):

1)需要在单独的行上使用分号(;)将变量声明与语句分开(至少在4.0版本之前)

    int i;
    int myArray[5];
    ;
    i = 1;

2)数组索引是基于1的,所以你不允许像in那样使用索引0(零)从数组中读取

    int myArray[5];
    ;
    print myArray[0];    // runtime error

这并不奇怪,但是你可以在赋值的左边使用0索引,比如in

    int myArray[5];
    ;
    myArray[2] = 102;
    myArray[0] = 100;    // this is strange
    print myArray[2];    // expcting 102?

会发生什么呢?数组被初始化为它的默认值,无论赋值中使用了什么值。上面的代码输出0(零)!

其他回答

在Java中,

String s = null;
System.out.println(s + "hello");

输出“nullhello”。

c# yield语句,并不奇怪,但非常有用。

http://msdn.microsoft.com/en-us/library/9k7k7cf0 (VS.80) . aspx

JCL条件返回执行。

//STEP02 EXEC PGM=PROG02,COND=(4,GT,STEP01) .

该特性允许您根据前面步骤的返回代码运行或不运行某个步骤。真是个不错的功能。

除了一些小功能,把逻辑颠倒过来。

首先,如果条件为真,则不运行步骤。

其次,4 GT,STEP01实际上意味着“如果STEP01的返回码大于4”

因此,整个过程意味着“如果来自STEP01的返回代码大于4,则不要运行此步骤”。这与“如果4大于来自STEP01的返回代码,则运行步骤”的简单解释几乎相同,但并不完全相同。

考虑到你唯一认真看待这些事情的时间是凌晨2点30分左右,电话另一端是一个疯狂的夜班接线员,这种双重模糊会导致严重的头痛。

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.

在Java中,

Int x = 010;

这将x赋值为8。

在Java中,任何前面带0的整数都被假定为八进制。