为了清楚起见,想要截断地址。不是在寻找改进的代码,只是为什么十六进制代码减法似乎无法正常工作。
从“cname”和“arptr”中减去“零”的第一个结果:
address of 'cname' is 0x7fff5fbff720
and of 'arptr' is 0x7fff5fbff720
为了清楚起见,想要截断不需要的数字,我减去 0x7fff5fbf0000 以为我会得到 0x00000000f720,但是:
从“cname”和“arptr”中减去“trunker”的第二个结果:
address of 'cname' is 0xffff00014082f720
and of 'arptr' is 0xffff00014082f720
#include <stdio.h>
#define trunker 0x7fff5fbf0000
#define zero 0x000000000000
int main(void) {
char cname[3][3] = {'a','b','c','e','f','g','i','j','k'};
char (* arptr)[3];
arptr = cname;
printf("address of cname is %p\nand of arptr is %p\n",
cname-zero,arptr-zero); //replace zero with trunker
//to truncate first 8 digits
return 0;
}
在 OS X 上使用 Xcode
谢谢和新年快乐 2012