Yet another printf question.

Started by
33 comments, last by Diodor 22 years, 4 months ago
HI

Sorry my first point is false. Maybe I''m not perfect? (sorry)

It did past 4 bytes for the integer value.

Thanks
Advertisement
HI

instead of:
burps_printf (" start\n %f\n %d\n %f\n end\n ", a, b, a);

Try this:
burps_printf (" start\n %f\n %f\n %f\n end\n ", a, b, a);

What Happens???

In burps function b is an integer but will be treated as a float and then will be converted to a double. Even though it is an integer. So the incorrect output will be displayed. Right.

And then try:
int *b = (int*)&a

burps_printf (" start\n %f\n %f\n %f\n end\n ", a, *b, a);

Do you get the same results???

Thanks
HI

Sorry again I finally understand what you are saying. (It''s amazing).

Yes the same 32 bits were passed and they were processed the same way.(float)

But why wouldn''t the value be converted to a double? Maybe It has something to do with how va_arg( l, double) works.
quote:Original post by xtrmntr
To get the answers you seek simply add this statement into your program and marvel at the beauty.

printf("\t\t\b\b\b");


Ehh. You could have added something like "don''t do this if you''re at work and have unsaved files" or something...
quote:
I was looking at the compiled asm, I understand what is happening.

Its pretty clear in the asm, but I'll explain anyway. printf needs to receive float's as double's, the 0.5f value is still being passed, it just not decoded because its not a double.


Apparently it wasn't clear to everybody.

Food for thought...

      float a = 0.5f;int b1 = 0;int *b2 = (int*)&aprintf("%f",b1,*b2|0x00e00000);    


prints 0.500000

Why, because I converted it to a double.

0.5f == 0x3f000000
double(0.5f) == 0x3fe0000000000000


Edited by - burp on November 21, 2001 7:03:29 PM

This topic is closed to new replies.

Advertisement