Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!decwrl!sgi!shinobu!odin!texas.asd.sgi.com!robert From: robert@texas.asd.sgi.com (Robert Skinner) Newsgroups: comp.sys.sgi Subject: Re: Possible C compiler bug? Message-ID: <1990Sep11.220607.19831@odin.corp.sgi.com> Date: 11 Sep 90 22:06:07 GMT References: <1379@cs.nps.navy.mil> Sender: news@odin.corp.sgi.com (Net News) Reply-To: robert@sgi.com Organization: Silicon Graphics Inc., Entry Systems Division Lines: 58 In article <1379@cs.nps.navy.mil>, spl@cs.nps.navy.mil (Steve Lamont) writes: |> I'm having a problem with a piece of C code on a 4D/70GT under 3.2. I have |> declared a variable as float (actually Coord but they're effectively the |> same). I pass it as a parameter to a function foo() and foo() passes it as a |> pointer to function bar(). When bar gets the float and dereferences the |> pointer, it finds a bogus value. It seems what C is doing is promoting the |> variable to a double even though it is declared as a float. |> |> ------------------------------------8<--------------------------------------- |> |> Here's what the SillyG returns: |> |> foo: 123.345001 123.345001 |> bar: 3.481816 123.345001 |> |> and here's what a BSD VAX 11/785 sez: |> |> foo: 123.345001 123.345001 |> bar: 123.345001 123.345001 |> |> |> spl (the p stands for |> perplexed over |> precision) |> -- |> Steve Lamont, SciViGuy -- (408) 646-2752 (subject to change at random) |> NPS Confuser Center / Code 51 / Naval Postgraduate School / Monterey, CA 93940 |> "You're okay," said Honeysuckle. "The dogs like you." |> - Charles Bukowski, "How to Get Published" also, if I remember correctly, the first 4 bytes of a VAX double look are exactly the same as the VAX float of the same number. So I think you could very well say this: print( float *v ); { ... double pi = 3.1415912937462386; print( &pi ); ... } and 'print' will print the correct single precision value for pi. So the VAX may be hiding the error from you. Robert Skinner robert@sgi.com Watch out where the Huskies go, and don't you eat that yellow snow. - Frank Zappa