I have this bit of code that is outputting the wrong results.
unsigned char bytes;
memcpy( &flt, bytes, 4);
printf("bytes 0x%x float %e\n", flt, flt);
the output that I get is
>bytes 0xc0000000 float -2.000001e+00
I am expecting to get
>bytes 0xdeadbeef float -6.2598534e+18
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前端其它相关文章！