看看这一法典:
这是一种结构化定义文件,有1个细化结构包装(用于储存联网)
#pragma pack(1)
typedef struct _TestStruct1 {
double d1;
double d2;
} TestStruct1;
typedef struct _TestStruct2 {
unsigned long v1;
unsigned short v2;
unsigned long v3;
unsigned long value;
TestStruct1 ts1;
} TestStruct2;
#pragma pack()
Ok. 下面是简单法典:
TestStruct2 wtf;
wtf.v1 = 0;
wtf.v2 = 0;
wtf.v3 = 0;
wtf.value = 4294967295;
wtf.ts1.d1 = 37.785834f;
wtf.ts1.d2 = 37.785834f;
char * cp = (char *)&wtf;
for (int i = 0; i < sizeof(TestStruct2); i++) NSLog(@"[%d] %d", i, (int)cp[i]);
NSLog(@"wtf.value: %lu", wtf.value);
传真XCode 4.2:
[0] 0
[1] 0
[2] 0
[3] 0
[4] 0
[5] 0
[6] 0
[7] 0
[8] 0
[9] 0
[10] -1
[11] -1
[12] -1
[13] -1
[14] 0
[15] 0
[16] 0
[17] 64
[18] -106
[19] -28
[20] 66
[21] 64
[22] 0
[23] 0
[24] 0
[25] 64
[26] -106
[27] -28
[28] 66
[29] 64
wtf.value: 4294967295
不存在问题。 但它涉及的是实际装置(iPhone4)。
[0] 0
[1] 0
[2] 0
[3] 0
[4] 0
[5] 0
[6] 0
[7] 0
[8] 0
[9] 0
[10] -1
[11] -1
[12] 0
[13] 0
[14] 0
[15] 64
[16] -106
[17] -28
[18] 66
[19] 64
[20] 0
[21] 0
[22] 0
[23] 64
[24] -106
[25] -28
[26] 66
[27] 64
[28] 88
[29] 84
wtf.value: 65535
oh my god what happen? I stored wtf.value with 4294967295, but on the device, it changes to 65535. this problem happens only on device, not on simulator.
这一问题从来就没有发生于SOS5 XCode4.2。
我怎么能够确定这一点? 请帮助我。