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

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


当前回答

我喜欢在C中插入八进制值:

int values[8] = { 123, 154, 103, 310, 046, 806, 002, 970 };

其他回答

在c++中,你可以做:

std::string my_str;
std::string my_str_concat = my_str + "foo";

但你不能:

std::string my_str_concat = "foo" + my_str;

操作符重载通常服从WTF。

C和c++中的三联体。

int main() {
   printf("LOL??!");
}

这将打印LOL|,因为trigraph ??!转换为|。

在C语言中,数组可以像这样被索引:

a[10]

这很常见。

然而,鲜为人知的形式(真正有效!)是:

10[a]

这与上面的意思相同。

在PHP中,字符串和函数指针一样好:

$x = "foo";
function foo(){ echo "wtf"; }
$x(); # "wtf"

不幸的是,这并不管用:

"foo"();

当今所有语言:

TypeA a = (TypeA)some_operation_returning_TypeB(1,2,3); // TypeB is not inheriting TypeA

在运行时失败,并带有"Cast to TypeA failed exception"-消息(或类似消息)。这告诉我们程序员到底有多懒。他们没有办法产生消息“未能将TypeA的变量‘a’与TypeB的值‘some_operation_returning_TypeB(1,2,3)’赋值”。他. .他们的座右铭是“犯错误的人必须受苦”。