[unix-pc.bugs] UNIX-PC Floating point weirdness

carver@bsadrc.UUCP (Darrel R. Carver) (02/10/89)

I have been having some strange problems with floating point
expressions in the UNIX-PC C compiler.  I am using the 3.51
development set.  The problem seems to occur when using *complex*
expressions involving floating point numbers. Consider the following
example:

1 >|	#include <stdio.h>
2 >|	
3 >|	struct RVAL {
4 >|		double ret_val;
5 >|		/* Other elements */
6 >|	};
7 >|	
8 >|	struct RVAL rval;
9 >|	
10>|	float fbug(f_return)
11>|	struct RVAL *f_return;
12>|	{
13>|		float a, b, c;
14>|	
15>|		a = b = c = 0.0;
16>|	
17>|		/* Some processing involving a, b, c */
18>|		return(f_return->ret_val = a);
19>|	}
20>|	
21>|	main()
22>|	{
23>|		fbug(&rval);
24>|	}

Now, compiling this program (call it ftest), I get this error:

>>>|	$ cc -o ftest ftest.c 
>>>|	 "ftest.c", line 18: compiler error: allocation fails, op STAR

If I change line 18 to

18>|		f_return->ret_val = a;
18x|		return(a);

It compiles, no problem.  I do not consider the second form
acceptable.  In addition some of the code I have from various sources
will do the type of assignments in the example.

I can usually go around this by breaking down the subexpression, but
it is annoying.  Any comments? flames?
-- 
Darrel R Carver	            -	A clever quote goes here.  Have we got any in
CommTek Publishing Company  -	the unquotable quotes?
Vienna, Va  22180           -
uunet!bsadrc!carver	    -			Mr. Bear

daveb@gonzo.UUCP (Dave Brower) (02/11/89)

In article <129@bsadrc.UUCP> carver@bsadrc.UUCP (Darrel R. Carver) writes:
>Now, compiling this program (call it ftest), I get this error:
>
>>>>|	$ cc -o ftest ftest.c 
>>>>|	 "ftest.c", line 18: compiler error: allocation fails, op STAR
>
>If I change line 18 to
>
>18>|		f_return->ret_val = a;
>18x|		return(a);
>
>It compiles, no problem.  I do not consider the second form
>acceptable.  In addition some of the code I have from various sources
>will do the type of assignments in the example.
>
>I can usually go around this by breaking down the subexpression, but
>it is annoying.  Any comments? flames?

Congratulations, you are now entering hacker/guru-hood in that you have
found a compiler bug and figured out an ugly but passable workaround.
With a 3b1, you are out of luck getting a fix from the vendor, so you
need to use form B or bust.

If you want a supported compiler, use gcc (:-(. sometimes, others :-).

-dB
-- 
If life was like the movies, the music would match the picture.

{sun,mtxinu,hoptoad}!rtech!gonzo!daveb		daveb@gonzo.uucp