kx 发帖数: 16384 | 1 【 以下文字转载自 Dreamer 讨论区 】
发信人: Dreamer (不要问我从哪里来), 信区: Dreamer
标 题: (麻烦转到jobhunting版)Splunk面经
发信站: BBS 未名空间站 (Fri Nov 1 12:33:13 2013, 美东)
--------------------------------------------
对方发来email,要求找以下三段code有什么问题:
1.
bool f(int x)
{
return !(x & 7);
}
2.
uint v[10];
uint i = 0;
while (i < 10)
v[i] = i++;
3.
bool f( uint n )
{
return (n & (n-1)) == 0;
}
这道题我只找到一个问题,就是调用f(n)时如果n是INT_MIN,那么返回true。
-------------------------------------------- |
s***e 发帖数: 403 | 2 这些函数的目的是什么?不给目的的话,只要不潜在crash就是正确的。 |
l***i 发帖数: 1309 | 3 problem 2, undefined behavior, because i is used in lhs and rhs and it is
not defined which side gets evaluated first |
l***i 发帖数: 1309 | 4 problem 1 seems to check whether input is a multiple of 8, since it masks
all high order bits, but then there is a problem if input is negative. |
w********g 发帖数: 106 | 5 which negative input causes problem? I checked 0, -8, -16, and -2147483648
(-2^31), all return true.
【在 l***i 的大作中提到】 : problem 1 seems to check whether input is a multiple of 8, since it masks : all high order bits, but then there is a problem if input is negative.
|
a***m 发帖数: 5037 | 6 C99 specification: "Between the previous and next sequence point an object
shall have its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to determine
the value to be stored."
google : sequence point
|
kx 发帖数: 16384 | 7 【 以下文字转载自 Dreamer 讨论区 】
发信人: Dreamer (不要问我从哪里来), 信区: Dreamer
标 题: (麻烦转到jobhunting版)Splunk面经
发信站: BBS 未名空间站 (Fri Nov 1 12:33:13 2013, 美东)
--------------------------------------------
对方发来email,要求找以下三段code有什么问题:
1.
bool f(int x)
{
return !(x & 7);
}
2.
uint v[10];
uint i = 0;
while (i < 10)
v[i] = i++;
3.
bool f( uint n )
{
return (n & (n-1)) == 0;
}
这道题我只找到一个问题,就是调用f(n)时如果n是INT_MIN,那么返回true。
-------------------------------------------- |
s***e 发帖数: 403 | 8 这些函数的目的是什么?不给目的的话,只要不潜在crash就是正确的。 |
l***i 发帖数: 1309 | 9 problem 2, undefined behavior, because i is used in lhs and rhs and it is
not defined which side gets evaluated first |
l***i 发帖数: 1309 | 10 problem 1 seems to check whether input is a multiple of 8, since it masks
all high order bits, but then there is a problem if input is negative. |
w********g 发帖数: 106 | 11 which negative input causes problem? I checked 0, -8, -16, and -2147483648
(-2^31), all return true.
【在 l***i 的大作中提到】 : problem 1 seems to check whether input is a multiple of 8, since it masks : all high order bits, but then there is a problem if input is negative.
|
a***m 发帖数: 5037 | 12 C99 specification: "Between the previous and next sequence point an object
shall have its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to determine
the value to be stored."
google : sequence point
|
f******n 发帖数: 346 | 13 看不出来1有什么毛病,8 变成-8 是反转然后+1,
00001000 -> 11111000
mask 是00000111,没有错啊 |
c********p 发帖数: 1969 | |