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

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


当前回答

C和c++中的三联体。

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

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

其他回答

在JavaScript中,你可以使用双位负(~~n)来代替Math.floor(n)(如果n是正数)或parseInt(n, 10)(即使n是负数)。N | N和N & N总是得到和~~ N相同的结果。

var n = Math.PI;
n; // 3.141592653589793
Math.floor(n); // 3
parseInt(n, 10); // 3
~~n; // 3
n|n; // 3
n&n; // 3

// ~~n works as a replacement for parseInt() with negative numbers…
~~(-n); // -3
(-n)|(-n); // -3
(-n)&(-n); // -3
parseInt(-n, 10); // -3
// …although it doesn’t replace Math.floor() for negative numbers
Math.floor(-n); // -4

单个位的求反(~)计算-(parseInt(n, 10) + 1),因此两个位的求反将返回-(-(parseInt(n, 10) + 1) + 1)。

更新:这里有一个jsPerf测试用例,比较了这些替代方案的性能。

哈哈!

整个语言本身。虽然不完全是WTF的事情,但我从来没有遇到过一种语言在我的脑海中以一种刺耳的卡通声音播放。我以前也从来没有看过代码并想要惊呼“啊啊啊啊可爱!”

这个程序显示数字1-10并终止

HAI
CAN HAS STDIO?
IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
    VISIBLE SUM OF VAR AN 1
IM OUTTA YR LOOP
KTHXBYE

Perl的许多内置变量:

$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is

还有很多这样的东西。点击这里阅读完整列表。

对我来说,它绝对是INTERCAL中的PLEASE修饰符。 如果PLEASE出现的次数不够多,则认为程序不够礼貌,错误消息如下所示;如果太频繁,这个程序可能会被认为过于礼貌而被拒绝。

In C

a[i++] = i;

它会编译,但很少执行您认为它应该执行的操作。优化更改会产生截然不同的结果。它在不同平台上的运行方式也不同。

然而,编译器对此非常满意。