Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!altos!vsi1!octopus!stever From: stever@Octopus.COM (Steve Resnick ) Newsgroups: comp.lang.c Subject: Re: Assinging values to type float Message-ID: <1990Aug28.170128.9359@Octopus.COM> Date: 28 Aug 90 17:01:28 GMT References: <90240.003415RHMCSUPV@MIAMIU.BITNET> Reply-To: stever@octopus.UUCP (Steve Resnick ) Organization: Octopus Enterprises, Cupertino CA Lines: 34 In article <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 */ > > Forgive me if I am wrong, and this is all supposition on my part, but I think that Microsoft C is a little more "strongly typed" in that when it sees a constant that will fit in an int, it assumes int for that type. when you assign it to a float, the compiler warns that you are putting and int value into a float. This should be OK, since the compiler should be assigning the value as if it were (float) 35, or 35.0. In orderd to avoid warnings like that, for float values which do not have a fractional portion, I always assign the value .0. Hope this helps... Steve -- ---------------------------------------------------------------------------- steve.resnick@f105.n143.z1@FIDONET.ORG #include Flames, grammar errors, spelling errrors >/dev/nul ----------------------------------------------------------------------------