Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!mcsun!tuvie!vmars!hp From: hp@vmars.tuwien.ac.at (Peter Holzer) Newsgroups: comp.lang.c Subject: Re: Assinging values to type float Message-ID: <1777@tuvie> Date: 28 Aug 90 18:13:27 GMT References: <90240.003415RHMCSUPV@MIAMIU.BITNET> Sender: news@tuvie Lines: 36 RHMCSUPV@MIAMIU.BITNET (Douglas M. MacFarlane) writes: >For example: > >float fValue ; /* define fValue as a floating point variable */ >fValue = 35 ; /* produces a Data Conversion warning at compile time */ > > >Whasss Happening ???? > MSC finds the integer 35, and an a float variable fValue so it figures out that 35 should really read 35.0. But this is a double value (all floating point constants are double) and through the assignment to a float bits could be lost, so the compiler warns you. The same effect happens if you do something like: char flag; flag = !flag; The char flag is promoted to int before the ! operation. The result (although in range [0..1]) is of type int, which is larger than a char ==> warning. If you do not like the warnings, use explicit casts. (One of the reasons why I prefer Turbo C over MSC is that you can enable and disable warnings individually) Hope I haven't confused you even more, Peter. -- | _ | Peter J. Holzer | Think of it | | |_|_) | Technische Universitaet Wien | as evolution | | | | | hp@vmars.tuwien.ac.at | in action! | | __/ | ...!uunet!mcsun!tuvie!vmars!hp | Tony Rand |