Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) Newsgroups: comp.lang.c Subject: Re: Assinging values to type float Message-ID: <667.26da7736@iccgcc.decnet.ab.com> Date: 28 Aug 90 18:52:54 GMT References: <90240.003415RHMCSUPV@MIAMIU.BITNET> Lines: 38 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 */ > > > Whasss Happening ???? > > Douglas M. MacFarlane > rhmcsupv@miamiu.acs.muohio.edu From the Microsoft C 5.1 user's guide, page 275: C4051 data conversion Two data items in an expression had different types, causing the type of one item to be converted. "fValue" is a float. "35" is an int. The compiler converted an int to a float for you. If you wanted a float, it thinks, you'd have written 35.0. (Of course 35.0 is actually a double, as are all floating-point constants, but that's another story.) -- Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A. (216) 371-0043 The opinions expressed are mine. Mine alone! Nobody else is responsible for them or even endorses them--except my cat Dexter, and he signed the power of attorney only under my threat to cut off his Cat Chow!