Assinging values to type float

Christopher R Volpe volpe at underdog.crd.ge.com
Wed Aug 29 07:21:10 AEST 1990


In article <667.26da7736 at iccgcc.decnet.ab.com>,
browns at iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes:
|>In article <90240.003415RHMCSUPV at MIAMIU.BITNET>,
RHMCSUPV at MIAMIU.BITNET (Douglas M. MacFarlane) writes:
|>>  
|>> 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.)

Ok, so which is it? Is the compiler complaining about the int-to-double
conversion for not writing 35.0? Or is it complaining about the
double-to-float conversion resulting in possible loss of precision?
Does the warning go away if you write "fValue=35.0;" or do you
need to write "fValue = (float) 35.0"?                                     
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list