我有以下 C/C++ 代码片段:
#define ARRAY_LENGTH 666
int g_sum = 0;
extern int *g_ptrArray[ ARRAY_LENGTH ];
void test()
{
unsigned int idx = 0;
// either enable or disable the check "idx < ARRAY_LENGTH" in the while loop
while( g_ptrArray[ idx ] != nullptr /* && idx < ARRAY_LENGTH */ )
{
g_sum += *g_ptrArray[ idx ];
++idx;
}
return;
}
Run Code Online (Sandbox Code Playgroud)
当我使用版本 12.2.0 中的 GCC 编译器编译上述代码时,并选择-Os两种情况:
g_ptrArray[ idx ] != nullptrg_ptrArray[ idx ] != …假设我有一个i来自外部来源的变量:
int i = get_i();
Run Code Online (Sandbox Code Playgroud)
假设i是INT_MIN和的补码表示形式,是-i不确定的吗?
问题问,
让 int x = 1,找到一个 int y 的值,其中以下语句将返回 false:
(x < y) == (-x > -y)
我知道答案应该是 4 个字节长(8 个十六进制数字),但我不知道如何解决这个问题。