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

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


当前回答

我最喜欢的奇怪的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).

其他回答

对于那些从未使用过COBOL的人来说,这是一个常见的代码行,但它不做您可能想做的事情

图片XXX

javascript:

parseInt('06'); // 6
parseInt('08'); // 0

我一直是PHP错误的忠实粉丝,当在一行中使用两个冒号时脱离上下文:

解析错误:语法错误,第3行/path/to/file/error.php中的T_PAAMAYIM_NEKUDOTAYIM异常

第一次遇到这种情况时,我完全被弄糊涂了。

学习PowerShell时发现:

试着猜一下结果数组是什么样的:

$a = 1, 2
$b = 1, 2+3
$c = 1, 2*3

答案:

1, 2
1, 2, 3
1, 2, 1, 2, 1, 2

哎哟!它动摇了我对PowerShell及其开发人员的信心。

在类C语言(包括C本身)中,你可以使用“向下到”操作符:

for (x = 20; x --> 0;) {
    print x;
}

这将打印从19到0的数字。