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

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


当前回答

在Java中,

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

输出“nullhello”。

其他回答

我最喜欢的c++语法小技巧是,你可以把URL(有一些限制)直接放到代码中:

int main( int argc, char *argv[] )
{
    int i=10;

    http://www.stackoverflow.com
    return 1;
}

这可以很好地编译。

语法高亮有点破坏了这个笑话,但它仍然很有趣。

我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:

void someWindowsFunction() {
    BITMAPINFOHEADER header = {sizeof header};

    /* do stuff with header */
}

这条微妙的线条达到了以下效果:

Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).

Perl:

可以编写一个完全由标点符号组成的程序。

这是怎么回事?!

在PHP中,必须显式地引用全局变量,并显式地使用这个->作为类变量。使重构变得有趣。如果不找到所有使用点,就不能将变量/参数提升为全局变量或类成员。

对于那些不知道的人,bc是一种“任意精度计算器语言”,我经常使用它进行快速计算,特别是当涉及的数字很大的时候($是提示符):

$ bc -lq
12^345
20774466823273785598434446955827049735727869127052322369317059031795\
19704325276892191015329301807037794598378537132233994613616420526484\
93077727371807711237016056649272805971389591721704273857856298577322\
13812114239610682963085721433938547031679267799296826048444696211521\
30457090778409728703018428147734622401526422774317612081074841839507\
864189781700150115308454681772032

bc在很长一段时间内都是标准的Unix命令。

现在是“WTF功能”。这是来自man bc(强调是我的):

quit:当读取quit语句时,bc处理器被终止, 不管在哪里找到quit语句。 例如,"if (0 == 1) quit"将导致bc终止。 halt: halt语句(扩展)是一个执行的语句 导致BC处理器仅在执行时退出。 例如,"if (0 == 1) halt"不会导致bc终止,因为停止没有执行。