Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have experimented with printf("%d\n", a); using gcc. When compiled for 32-bit x86, it displays the lower 32 bits of the double (which for 12.5 happen to be all 0).

On x86-64, it displays a random value each time, which actually happens to be some pointer (randomised by ASLR). This is because register passing is used on x86-64, and the the double is stored into a floating point register, but %d reads from a different register.

printf("%d\n", * (int*)&a); produces the number 1095237632 for both x86 and x86-64.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: