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

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


当前回答

在Java中,字符串如何处理==操作符取决于它是如何构造的,这存在一些不一致性。

String a = "Hello";
String b = "Hello";
System.out.println(a == b ); // prints true.
String c = new String("Hello");
String d = new String("Hello"); 
System.out.println(c == d ); // prints false

其他回答

我认为这实际上不是一个“语言特性”(C),我很可能在发布它时很无知,但我不知道为什么会发生这种情况,所以我会问。如果它被证明与一些奇怪的语言特征有关…这真的让我很不爽,所以这个地方是值得的。

int a = 0;
int *p = &a;

printf("%d, %d, %d.\n", *p, (*p)++, *p); // Outputs "1, 0, 0.\n" on MinGW's GCC 4.4.1

Why?

——编辑

刚拿到的,没什么大不了的。我能感觉到c++大师们现在在嘲笑我。我猜函数参数计算的顺序是未指定的,所以编译器可以自由地调用它们(我想我已经在boost的文档中读到过)。在本例中,实参语句是向后求值的,这可能反映了函数的调用约定。

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

我喜欢这类东西在JavaScript中很好的事实:

var futureDate = new Date(2010,77,154);
alert(futureDate);

结果是距离2010年第0个月的第0天77个月零154天,即2016年11月1日

对于那些不知道的人来说,PostScript实际上是一种编程语言。我已经有点疯狂了——我写了一个PostScript程序,计算曼德尔布罗特分形的细节非常高。它真的是可打印的PostScript,尽管它会崩溃很多打印驱动程序…

总之,从哪里开始PostScript…这里有一个例子:您实际上可以创建一个标识符为....的变量什么都没有。

() cvn 5 def %将数字5分配给…没有什么

PostScript是一种基于堆栈的语言。()将一个空字符串放入堆栈。cvn将其转换为一个名称(如果打印它,则为“/”,因为PS中的所有名称前面都有斜杠)。然后5def将值5赋给它。(%是注释字符)

你不能直接把它拿回来,例如,如果我说“/ print”,这将不会打印数字5。但你可以间接地把它拿回来:

() CVN负载打印%这将打印数字5

还有什么……PostScript将字典作为原生类型,您可以使用数组引用作为字典的键…但是REFERENCE才是键,而不是数组。所以:

/myDict 100 dict def

[0] dup myDict exch 42 put myDict exch get == %打印42

myDict [1] 42 put myDict [1] get %抛出未定义错误

编辑:哦,是的,还有一件有趣的事情……在Ghostscript提示下尝试以下操作:

1 array dup dup 0 exch put ==

分析!

大约20年前,我用一个编译器为一种叫做Coral的语言工作,它允许我声明只写变量!

不过,这是有道理的,因为它们是全球性的,被用作一种信号机制。一个进程写入值,另一个进程读取值。