memcpy not doing as it is supposed to

I have this bit of code that is outputting the wrong results. #include #include int main() { unsigned char bytes[4]; float flt=0; bytes[0]=0xde; bytes[1]=0xad; bytes[2]=0xbe; bytes[3]=0xef; memcpy( &flt, bytes, 4); printf("bytes 0x%x float %e\n", flt, flt); return 0; } the output that I get is >bytes 0xc0000000 float -2.000001e+00 I am expecting to get >bytes 0xdeadbeef float -6.2598534e+18 edit #1 as was pointed out the endianness could be different which would result in the following >bytes 0xefbeadde float -1.1802469e+29 what I don't understand is the cast from float to unsigned int resulting in 0xc0000000 (the float in the same printf statement being -2.0000 I would attribute to compiler optimization) this was working before on a different computer. It could be an architecture change.

以上就是memcpy not doing as it is supposed to的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准