【发布时间】:2020-09-11 18:14:57
【问题描述】:
所以我是使用 GDB 的新手,我正在使用以下程序作为练习
#include <stdio.h>
#include <stdlib.h>
int main() {
unsigned int value1, abs_value1, abs_value2, abs_value3;
int value2, value3;
char myarray[10];
printf("Enter 10 characters:");
fgets(myarray, 11, stdin);
printf("Enter an integer between 0 and 10,000:");
scanf("%d", &value1);
abs_value1 = abs(value1);
printf("Enter an integer between -10,000 and 0:");
scanf("%d", &value2);
abs_value2 = abs(value2);
printf("Enter an integer between -10,000 and 10,000:");
scanf("%d", &value3);
abs_value3 = abs(value3);
// set breakpoint here
return 0;
}
我输入的值如下...
myarray[10] = "characters"
value1 = 578
value2 = -1123
value3 = 999
运行一些命令后,我得到以下输出...
x/1x myarray : 0x63
x/1c myarray : 99 'c'
x/1s myarray : "characters"
x/1d &abs_value1 : 578
x/1x &value1 : 0x00000242
x/1d &abs_value2 : 1123
x/1x &value2 : 0xfffffb9d
x/1d &abs_value3 : 999
x/1x &value3 :0x000003e7
x/1c &value1 : 66 'B'
x/1c &value2 : -99 '\235'
所以我的问题是,不看代码,只使用前面的命令,我们能否判断 value1、value2 和 value3 是有符号还是无符号?
据我所知,我认为没有足够的信息来判断它们是签名还是未签名。我的第一直觉是寻找负值,但由于我们取变量的绝对值,因此无法确定该值是否以仅查看命令的负数开始。
如果变量是有符号的还是无符号的,我们可以用一些不同的方法来推断吗?
【问题讨论】: