在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
我最喜欢的奇怪的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).
其他回答
在c#中,你可以在接口上使用new操作符。
在C。
int;
(&a)[0] = 10;/*将值10赋给*/
[0]等于*(&a +0)得到*(&a)也就是a。
在Forth中,任何不包含空格的东西都可以是标识符(包含空格的东西需要做一些工作)。解析器首先检查事物是否定义了,在这种情况下,它被称为单词,如果没有,则检查它是否为数字。没有关键字。
无论如何,这意味着人们可以重新定义一个数字来表示其他东西:
: 0 1 ;
它创建了单词0,由1组成,不管它在执行时是什么。反过来,它会导致以下结果:
0 0 + .
2 Ok
另一方面,定义可以接管解析器本身——这是可以做到的 通过评论词。这意味着Forth程序实际上可以在中途变成一个完全不同语言的程序。事实上,这是Forth推荐的编程方式:首先你写你想要解决问题的语言,然后你解决问题。
这是我最喜欢的一个,你可以在Java中不使用main()来执行println。
这将编译和运行,给出println,但也有一个异常(java.lang。NoSuchMethodError:主要)
class Test {
static {
System.out.println("I'm printing in Java without main()");
}
}
转变;
有时你会在perl方法的第一行中看到它来读取self指针