What you do is undefined behavior. The format specifier is %p promises, which you pass to the pointer (in particular, the void* pointer), and instead you pass double ( float ) to get the double value when passing to variational functions like printf ). Thus, as soon as you do not satisfy the requirement, the compiler and implementation will be free to do whatever they want, and listing 0 instead of 85 in the second case is completely legal.
What can happen is that the compiler uses a calling convention that puts floating-point values โโin separate registers (for example, the x87 floating-point stack or SIME SSE2 registers) instead of the stack, while integer values โโlike pointers are passed to stack. Therefore, when the implementation sees the %p format specifier, it tries to read the argument from the stack, when in fact the argument is actually in a different place.
As already mentioned, you really have to compile with the -Wall option (assuming GCC or a GCC compatible compiler). This will help you catch such errors.
source share