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

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


当前回答

在C或c++中,使用宏可以获得很多乐趣。如

#define FOO(a,b) (a+b)/(1-a)

如果传入FOO(bar++,4),它将使a增加两次。

其他回答

Java源文件可以以字符\u001a (control-Z)结尾。

我肯定会给Perl提供多个可怕的例子:

if(!$#var)

or

if($mystring =~ m/(\d+)/) {

我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:

void someWindowsFunction() {
    BITMAPINFOHEADER header = {sizeof header};

    /* do stuff with header */
}

这条微妙的线条达到了以下效果:

Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).

在Perl中,可以通过修改一个类的@ISA数组来改变它的继承链,这让我很惊讶。

package Employee;
our @ISA = qw(Person);
# somwhere far far away in a package long ago
@Employee::ISA = qw(Shape); 
# Now all Employee objects no longer inherit from 'Person' but from 'Shape'

不知道有没有人提过。

在Java中,在finally块中它可以返回一个值。它将停止异常的传播并覆盖正常的return语句。