Assinging values to type float

Steve Resnick stever at Octopus.COM
Wed Aug 29 03:01:28 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 */
> 
> 
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 <number>.0. 
Hope this helps...

Steve


-- 
----------------------------------------------------------------------------
steve.resnick at f105.n143.z1@FIDONET.ORG #include<std_disclaimer.h>
Flames, grammar errors, spelling errrors >/dev/nul
----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list