English 中文(简体)
缩略语
原标题:iOS5 Xcode4.2 floating-point byte align error?

看看这一法典:

这是一种结构化定义文件,有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。

我怎么能够确定这一点? 请帮助我。

最佳回答

我有这样一个问题,涉及浮点错误计算,但涉及“协调”定位编码。 我确定,增加:

-mno-thumb

“其他旗帜”选择,在“建筑环境中,armv6 只使用“设计”和“附加条件”装置。

我不想确切了解这里发生的情况,而是补充说,这套建筑使你重新脱掉了Thumb指令,据一些人称(没有建议停用车。 管道改变浮动点计算工作的方式。

问题回答




相关问题
Haskell minimum/maximum Double Constant

Is there any way in Haskell to get the constant that is the largest and smallest possible positive rational number greater than zero that can be represented by doubles?

integer automatically converting to double but not float

I have a function like below: void add(int&,float&,float&); and when I call: add(1,30,30) it does not compile. add(1,30.0,30.0) also does not compile. It seems that in both cases, it ...

Lower Bounds For Floating Points

Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)?

Floating point again

Yesterday I asked a floating point question, and I have another one. I am doing some computations where I use the results of the math.h (C language) sine, cosine and tangent functions. One of the ...

热门标签