我编写的程序需要两个数字,然后进行除法和模运算。
代码是
#define ADDRESS_SPACE 4294967295
int main (int argc, char *argv[]) {
long int pagesize = atoi(argv[1]), virtaddr = atoi(argv[2]);
if (virtaddr >= ADDRESS_SPACE) {puts("Address is too large"); return 1;}
printf("%lu\n", virtaddr);
printf("%lu\n", ADDRESS_SPACE);
printf("Page = %lu\nOffset = %lu\n", virtaddr/pagesize, virtaddr%pagesize);
return 0;
}
并./page 1024 9999999999999999999999999999999999999999999999
给出以下输出
18446744073709551615
4294967295
Page = 0
Offset = 18446744073709551615
如果virtaddr
大于ADDRESS_SPACE
,为什么 if 语句不起作用?我知道有溢出,但打印变量不会显示任何错误,它们仍然是数字(long int 可以采用的最大值)。