iOS5 Xcode4.2 floating-point byte align error?

后端 未结 2 1663
执念已碎
执念已碎 2021-01-26 08:09

Look at this code:

this is struct definition file with 1byte struct packing (for socket networking)

#pragma pack(1)

typedef struct _TestStruct1 {

doubl         


        
相关标签:
2条回答
  • 2021-01-26 08:44

    And according to that same person (in reference to Craig's answer), that is, me, in that very same post, handling misaligned data on ARM is very bad (the simulator is x86). I can understand it for integers in network code (though I'd rather explicitly serialize), but there should be no reason to ever have misaligned floating-point numbers (here when you store the floating-point value it seems to be silently realigned to a 4-byte boundary and it overwrites part of wtf.value). You are not transmitting raw floating-point values over the network, right? Right?

    0 讨论(0)
  • 2021-01-26 08:58

    I had a problem like this, involving floating-point miscalculations but in UI positioning code. I fixed it by adding:

    -mno-thumb
    

    to the "Other C Flags" options under Build Settings, for armv6 devices only ("Add Build Setting" > "Add Conditional Setting").

    I don't pretend to understand exactly what's happening here, but by adding this build setting you're disabling the Thumb instruction set, which according to some (http://wanderingcoder.net/2010/07/19/ought-arm/) is not recommended for armv6 builds anyway. Thumb changes the way floating-point calculations work.

    0 讨论(0)
提交回复
热议问题