Assinging values to type float

Peter Holzer hp at vmars.tuwien.ac.at
Wed Aug 29 04:13:27 AEST 1990


RHMCSUPV at 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 at vmars.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!vmars!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list