Possible C compiler bug?

Robert Skinner robert at texas.asd.sgi.com
Wed Sep 12 08:06:07 AEST 1990


In article <1379 at cs.nps.navy.mil>, spl at 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
|> 							precicion)
|> -- 
|> Cteve 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;

	prind( &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 at sgi.com

	Watch out where the Huskies go,
	and don't you eat that yellow snow.

			- Frank Zappa



More information about the Comp.sys.sgi mailing list