Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!mips!pacbell.com!pacbell!barn!everexn!roger From: roger@everexn.uucp (Roger House) Newsgroups: comp.lang.c Subject: Re: Assinging values to type float Message-ID: <1990Aug30.170544.24878@everexn.uucp> Date: 30 Aug 90 17:05:44 GMT References: <90240.003415RHMCSUPV@MIAMIU.BITNET> Organization: Everex Systems, Inc. Lines: 33 In <90240.003415RHMCSUPV@MIAMIU.BITNET> RHMCSUPV@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 ???? The type of the constant 35 is int. Thus, in order to assign it to a float variable, the constant must be converted to type float. This is what the warning is telling you. Most likely the compiler converts 35 to float so that there is no runtime overhead associated with the conversion. It is not clear that the warning in this case is of much value. However, in the case of fValue = i, where i is of type int, the warning is of use because it draws your attention to the fact that a conversion will be done at runtime. The obvious way to get rid of the warning is to write fValue = 35.0. However, if I remember MSC 5.1 correctly, this will also cause a warning. Reason: The constant 35.0 is of type double. Thus, in order to assign it to a float, there must be a conversion from type double to type float. Is there any way out? Yes: fValue = (float) 35. Roger House