Mail Archives: djgpp/1994/11/20/18:47:02
> long i = 10 ;
> float x , y , z ;
> double w ;
>
> printf( "i=%8.8XH, x=%8.8XH, y=%8.8XH, z=%8.8XH\n", i, x, y, z );
> -------------------------------8<---cut here--->8-------------------------------
> long is: 4 bytes, float is: 4 bytes, double is: 8 bytes.
> i=0000000AH, x=40240000H, y=00000000H, z=40240000H
> i=10, x=10, y=10, z=1.4013e-44
> -------------------------------8<---cut here--->8-------------------------------
>
> Huh?
>
> Variables x and z hold the same bit pattern, but x and y give the same results?
ANSI states that floats are promoted to double when passed to a
function with a formal prototype type of "...". Thus, you are passing
8 bytes per float, not 4, and taking up two %X per float instead of
just one. You need to use this:
*(int *)(&x)
to pass only the four bytes of the float variable itself.
- Raw text -