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

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


当前回答

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

a[10]

这很常见。

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

10[a]

这与上面的意思相同。

其他回答

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

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

C和c++中的三联体。

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

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

在Forth中,任何不包含空格的东西都可以是标识符(包含空格的东西需要做一些工作)。解析器首先检查事物是否定义了,在这种情况下,它被称为单词,如果没有,则检查它是否为数字。没有关键字。

无论如何,这意味着人们可以重新定义一个数字来表示其他东西:

: 0 1 ;

它创建了单词0,由1组成,不管它在执行时是什么。反过来,它会导致以下结果:

0 0 + .
2 Ok

另一方面,定义可以接管解析器本身——这是可以做到的 通过评论词。这意味着Forth程序实际上可以在中途变成一个完全不同语言的程序。事实上,这是Forth推荐的编程方式:首先你写你想要解决问题的语言,然后你解决问题。

回想起来,FORTRAN的计算goto是相当奇怪的。维基百科告诉我一些基础知识胜过它。

另一个著名的最爱是Algol 60的名称参数调用传递。

Powerbasic (www.powerbasic.com)包含编译器指令:

# BLOAT {bloatsize}

这将使编译后的可执行文件的大小增加<bloatsize>字节。这是放在编译器中,以防创建可执行文件的人不喜欢生成的可执行文件的小尺寸。它使EXE看起来更大,以与臃肿的编程语言竞争:)