When I ran the following code:
printf("%d %f %d %d %f\n", 1.2 , 3000, 2.5, 400, 500);
What I thought was the answer might be some meaningless number, but the result was actually:
3000 1.200000 400 500 2.500000
which is just the same number and in the same format as my input.
It was so meaningful that I can't persuade myself ignoring it.
Could someone tell me the reason? I would be very grateful.
p.s. I'm using Clion as my IDE.
Just a guess: On your ABI floating point arguments are passed via the FPU stack, integers through the CPU-stack. So when printf pulls the arguments, it pulls
%f
s from the FPU stack and pops%d
s off the CPU-stack. If I am right,printf("%d %d %d ***** %f %f\n", 1.2 , 2.5, 3000, 400, 500);
should work for you too. So the mixup between floats and others (%d, %s & Co) will be recovered for you, the order is preserved. Needless to add: all this is >150% UB.