在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
Duff的C语言设备!
在C语言中,可以将do/while语句与switch语句交错使用。下面是memcpy使用此方法的示例:
void duff_memcpy( char* to, char* from, size_t count ) {
size_t n = (count+7)/8;
switch( count%8 ) {
case 0: do{ *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
}while(--n>0);
}
}
其他回答
在php中:
easter_date -获取给定年份复活节午夜的Unix时间戳
Int easter_date ([Int $year])
在Ruby中,你可以用heredocs做一些奇怪的事情。考虑:
a = <<ONE
This is one. #{<<TWO}
This is two. #{<<THREE}
This is three.
THREE
TWO
ONE
p a # => "This is one. This is two. This is three.\n\n\n"
Processing (processing.org)是一种基于Java的语言。简单来说,处理编译器是将特定于处理的语法转换为Java的Java预处理器。
由于语言的设计,它有一些惊喜:
Processing的类被编译成Java内部类,这会引起一些麻烦,比如私有变量并不是真正私有的
class Foo {
private int var = 0; // compiles fine
}
void setup() {
Foo f = new Foo();
print(f.var); // but does not causes compile error
}
同样缺少draw()函数会导致事件处理程序不被调用:
// void draw() {} // if you forgot to include this
void mousePressed() {
print("this is never called");
}
在JavaScript中:
2 == [2]
//更陌生 2 == [[[2]]]
//和彻头彻尾的坚果 Var a = {"abc": 1}; A [[[["abc"]]]] === A ["abc"];//这也是正确的
幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切:http:/stackoverflow.com/questions/1724255/why-does-2-2-in-javascript
在C语言中,
int x = 1;
int y = x++ + ++x;
printf("%d", y);
是模棱两可的,打印什么取决于编译器。编译器可以在计算++x之前或在语句的末尾存储x++的新值。