在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在x++ (Microsoft Dynamics AX):
1)需要在单独的行上使用分号(;)将变量声明与语句分开(至少在4.0版本之前)
int i;
int myArray[5];
;
i = 1;
2)数组索引是基于1的,所以你不允许像in那样使用索引0(零)从数组中读取
int myArray[5];
;
print myArray[0]; // runtime error
这并不奇怪,但是你可以在赋值的左边使用0索引,比如in
int myArray[5];
;
myArray[2] = 102;
myArray[0] = 100; // this is strange
print myArray[2]; // expcting 102?
会发生什么呢?数组被初始化为它的默认值,无论赋值中使用了什么值。上面的代码输出0(零)!
其他回答
PHP
来自在线文档: string implode (string $glue, array $pieces) -用字符串连接数组元素 注意:由于历史原因,implode()可以以任意一种顺序接受其形参。
这是可行的:implode($someArray, $glue)
希望他们能在PHP 6中消除这些历史怪癖。
有趣的自动装箱和Java中的整数缓存:
Integer foo = 1000;
Integer bar = 1000;
foo <= bar; // true
foo >= bar; // true
foo == bar; // false
//However, if the values of foo and bar are between 127 and -128 (inclusive)
//the behaviour changes:
Integer foo = 42;
Integer bar = 42;
foo <= bar; // true
foo >= bar; // true
foo == bar; // true
解释
快速浏览一下Java源代码将会出现以下内容:
/**
* Returns a <tt>Integer</tt> instance representing the specified
* <tt>int</tt> value.
* If a new <tt>Integer</tt> instance is not required, this method
* should generally be used in preference to the constructor
* {@link #Integer(int)}, as this method is likely to yield
* significantly better space and time performance by caching
* frequently requested values.
*
* @param i an <code>int</code> value.
* @return a <tt>Integer</tt> instance representing <tt>i</tt>.
* @since 1.5
*/
public static Integer valueOf(int i) {
if (i >= -128 && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
else
return new Integer(i);
}
注意:IntegerCache。High默认为127,除非由属性设置。
自动装箱的情况是,foo和bar都是从缓存中检索到相同的整数对象,除非显式创建:例如,foo = new integer(42),因此在比较引用是否相等时,它们将为真而不是假。比较Integer值的正确方法是使用.equals;
C和c++中的三联体。
int main() {
printf("LOL??!");
}
这将打印LOL|,因为trigraph ??!转换为|。
在C或c++中,使用宏可以获得很多乐趣。如
#define FOO(a,b) (a+b)/(1-a)
如果传入FOO(bar++,4),它将使a增加两次。
ANSI SQL中空值的三值逻辑。