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

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


当前回答

另一个C-ism。

int i= 0;
while( i != 12 ) {
    /* Some comment 
    i += 1;
    /* Another comment */
}

为什么不行?棉绒会告诉你。然而,C编译器通常会轻松地忽略这一点。我也是。

当我发现问题出在哪里的时候,那真是太棒了。

其他回答

A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.

在Java中,如果x的值为NaN,则x == x返回false, x != x返回true。

在PHP中,你可以使用符号和字符串文字或包含变量名的变量引用变量,例如:

${'foo'} = 'test';
echo $foo;

这将打印“test”。这种行为的奇怪之处在于,你也可以使用非字符串作为变量名,例如:

${array()} = 'test';
echo ${array()};
${NULL} = 'test';
echo ${NULL};

现在我们有了名为array()的变量,甚至还有NULL!所有包含字符串"test"。

在c++中,你可以从空指针调用静态方法——看!

class Foo {
  public:
    static void bar() {
      std::cout << "WTF!?" << std::endl;
    }
};

int main(void) {
  Foo * foo = NULL;
  foo->bar(); //=> WTF!?
  return 0; // Ok!
}

这句话让我很意外……

Fortran中不同列的特殊含义。(如果你从小就有穿孔卡片,这可能是很自然的。)

这样做的一个副作用是,例如变量名在第72列之后被截断。结合隐式NONE,当这样的变量名在第72列附近开始时,它会无声地引入一个新变量。

你需要

要知道这一点 以不同的方式高亮显示注释部分(第72列之后)的编辑器 颜色比之前的部分…