Mail Archives: djgpp/1994/11/19/16:43:27
> Consider:
>
> float x, y;
> long i = 10;
>
> /* assume sizeof (float) == sizeof (long) */
>
> x = (float) i;
> y = *(float *) &i;
>
> Here `x' will have the value of 10.0 whereas `y' has the bit
> pattern that you re suggesting above. `y' will will almost
> certainly not be 10.0 and `x' will not have the bit pattern of `i'.
> That is, the float cast above will definitely modify the bit
> pattern of i.
>
>This example is bogus because
>
> x = i;
>
>will work without the cast, and it means (in K&R C)
>
> x = (float) (double) i;
Just because I used an explicit cast in the conversion of int to float does
not make the example bogus. I think the example illustrates the point
quite well, in fact, I believe that it would not be as effective without the
cast.
--John
- Raw text -