所以我有一个返回 unsigned char * 的方法
unsigned char* someMethod(num)
unsigned short num;
{
//do some stuff with num and change values of a
unsigned char * a = (unsigned char*) malloc(4);
printf("a0 is %x\n",a[0]);
printf("a1 is %x\n",a[1]);
printf("a2 is %x\n",a[2]);
printf("a3 is %x\n",a[3]);
return a;
}
当我调用 someMethod(128) 时:
unsigned char* s = someMethod(128);
printf("s0 is %x\n",s[0]);
printf("s1 is %x\n",s[1]);
printf("s2 is %x\n",s[2]);
printf("s3 is %x\n",s[3]);
它会打印出来
a0 is 30
a1 is 1
a2 is 31
a3 is 30
s0 is 30
s1 is 14
s2 is ffffff9d
s3 is 0
这对我来说毫无意义,因为我分配了 s = someMethod(128)。a 和 s 不应该具有相同的值吗?!?任何帮助表示赞赏。谢谢!