Assinging values to type float

Stan Brown, Oak Road Systems browns at iccgcc.decnet.ab.com
Wed Aug 29 04:52:54 AEST 1990


In article <90240.003415RHMCSUPV at MIAMIU.BITNET>, RHMCSUPV at MIAMIU.BITNET (Douglas M. MacFarlane) writes:
> Excuse the novice question . . .
>  
> I'm new to C and liking it, but this puzzles me.  I'm using Microsoft
> C ver 5.1.   When I assign a value to a float variable, I get a data-
> conversion warning (with warning level 2 set).  Why?
>  
> For example:
>  
> float fValue ;     /* define fValue as a floating point variable  */
>  
> other lines
>  
> fValue = 35 ;     /* produces a Data Conversion warning at compile time */
>  
>  
> Whasss Happening ????
>  
> Douglas M. MacFarlane
> rhmcsupv at miamiu.acs.muohio.edu


>From the Microsoft C 5.1 user's guide, page 275:

C4051  data conversion
       Two data items in an expression had different types, causing
       the type of one item to be converted.

"fValue" is a float.  "35" is an int.  The compiler converted an int to a
float for you.  If you wanted a float, it thinks, you'd have written 35.0.
(Of course 35.0 is actually a double, as are all floating-point constants,
but that's another story.)
-- 

Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A.         (216) 371-0043
The opinions expressed are mine. Mine alone!  Nobody else is responsible for
them or even endorses them--except my cat Dexter, and he signed the power of
attorney only under my threat to cut off his Cat Chow!



More information about the Comp.lang.c mailing list