From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: weird gcc thing Date: Mon, 17 Feb 1997 20:32:26 -0800 Organization: Two pounds of chaos and a pinch of salt Lines: 31 Message-ID: <330930DA.5A49@cs.com> References: <5eaiu2$j08 AT flex DOT uunet DOT pipex DOT com> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp204.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp nikki wrote: > > i eventually figured this one out, it can be solved by ensuring a #include > presumably linux and sunos were doing this automatically or > something. but it struck me as weird behavior nonetheless, after all it > compiled fine (ok -Wall would say implicit declaration, but you can do that > with printf in the example above and printf has the correct behavior?) Ahhh... this is a programming mistake on your part. You MUST ALWAYS include the appropriate header files so that the compiler knows what data type a function is supposed to return! In the case above, atof() is being implicitly declared to return an integer, not a float, which gets passed to printf() as a 4 byte entity. Since printf() expects to see 8 bytes for the '%f' specifier, it only grabs half of the value returned from atof() and goes apeshit. :) In practice, it can become even more complex than that, because atof() really _does_ return a float... Simple answer: always, always, include the right header files! If you had compiled with '-Wall', you'd have been warned about implicit declaration of 'atof', and also about mismatched parameters to printf(). '-Wall' is the programmer's life preserver. Omit it at your own risk. -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | | * Proud user of DJGPP! * | http://www.cs.com/fighteer | | ObJoke: If Bill Gates were a robber, not only would he | | shoot you, but he'd send you a bill for the bullets. | ---------------------------------------------------------------------