bug in cc (???)

Tom Stockfisch tps at sdchema.UUCP
Thu Sep 5 07:34:37 AEST 1985


[]
[Repost--  previous submission got mangled]

Todd Olson writes that the 4.2 C compiler can't handle
	
	int	n;
	struct S {
		int a;
		int b;
	} *X[2][2],
	.
	.
	.
	f( *X[n][0] );	/* cc complains on this line */

I think there are _many_ bugs in the way 4.2 handles passing whole structures.
Consider the following bug bite I received which prevents me from treating
complex numbers as primitives.  The gyst is that you can't immediately
access a member of a structure returned by a function.  Very frustrating.


/* C stuff trying to deal with complex numbers as primitives */

typedef struct {
	double re;
	double im;
} complex;

main()
{
	complex		topolar();
	double		mag;
	complex		c2;
	static complex	c1 = { 1.0, 2.0 };

/*###18 [cc] structure reference must be addressable%%%*/
	mag =	topolar(c1).re;			/* sure would be nice if I
						 * could do this
						 */

/*###21 [cc] structure reference must be addressable%%%*/
	mag =	( c2 = topolar(c1) ).re;	/* even this doesn't work */

	/* you have to break it into two separate statements--this works */
	c2 =	topolar(c1);
	mag =	c2.re;
}

complex
topolar( z )		/* convert z to polar form */
	complex	z;
{
	complex	polar;
	double	hypot(),	atan2();

	/* details not related to bug */
	polar.re =	hypot( z.re, z.im );
	polar.im =	atan2( z.im, z.re );
	return	polar;
}

/* end of program */

I sure hope 4.3 fixes this.

			--Tom Stockfisch
			  UCSD Chemistry



More information about the Comp.bugs.4bsd.ucb-fixes mailing list