CSAPP数据实验室(isTmax):!好像不起作用

问题描述 投票:0回答:1

我的想法就像这个问题。 我的代码 isTmax 是这样的:

int isTmax(int x) {
  return  !((~x)+(~x)); // it should be right, the operator "!" seem to not work
}

x 是 2 的补码,整数的 32 位表示 当我使用 btest 测试功能时,它生成如下:

错误:测试 isTmax(2147483647[0x7fffffff]) 失败... ...给出 0[0x0]。应该是 1[0x1]

我的问题是:为什么是0?这好像是 !没工作。

此外,我在运行 btest 时收到警告:

btest.c:在函数“test_function”中: btest.c:334:23:警告:“arg_test_range”可能在未初始化的情况下使用[-Wmaybe-uninitialized] 334 | 334如果(arg_test_range[2] < 1) | ~~~~~~~~~~~~~~^~~ btest.c:299:9: note: ‘arg_test_range’ declared here 299 | int arg_test_range[3]; /* test range for each argument */ | ^~~~~~~~~~~~~~

也许我的实验室环境有问题?

c bit twos-complement
1个回答
0
投票

这只是一个警告消息,不会影响您的测试。您可以在 makefile 中使用

-w
来忽略此警告

© www.soinside.com 2019 - 2024. All rights reserved.