Re: The printf format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 14 Jan 2013 19:29:19 +0800 GHui wrote:
> I code the following code.
> --------------------------
> #include <stdio.h>
> int main(int argc,char **argv)
> {
>     float f[2]={4.0, 37.4};
>     printf("%.2f    %.2f\n",f[0],f[1]);
>     printf("%d    %.2f\n",f[0],f[1]);
> }
> 
> And it output is following.
> -------------------------
> 4.00    37.40
> -1    4.00
> 
> I confuse that f[1] is 4.00 at the second line.
> Any help will be appreciated.
> 

Off the top of my head: the second printf pulls the argument for "%d"
from the general set of registers, while the one for "%.2f" is taken
from the SSE registers. At least on amd64. For x86 it has something to
do with how the float arguments are placed on stack (unlike int-s). You
can probably get a better image with:

  $ objdump -D -C -l -j .text <binary> | vim -

-- 
Mihai Donțu



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux