[comp.lang.c] ANSI Oct 86 Public draft

ksb@j.cc.purdue.edu.UUCP (04/01/87)

In article <5708@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>It occurs to me that an example of why C floating == is not very useful
>might be in order (apart from the numerical analysis problems):
>
>	#include <stdio.h>
>
>	int SameRatio( a, b, c, d )	/* return non-0 iff a/b == c/d */
>		register double	a, b, c, d;
>		{
>		register double	ab = a / b;	/* `register' honored */
>		register double cd = c / d;	/* `register' ignored */
>
>		return ab == cd;
>		}
>
>	int main()
>		{
>		static double	a = 2.0, b = 3.0, c = 2.0, d = 3.0;
>
>		(void)printf( "%s\n", SameRatio( a, b, c, d ) ? "ok" : "oops" );
>		return 0;
>		}
>
>Now suppose that the machine has 5 available FP registers (other than the
>scratch accumulators), that they include some guard bits, and that no real
>optimization is done.  Since `cd' will be stored in memory, for the ab == cd
>comparison it will be loaded into a scratch register with its guard bits set
>to zero, unlike `ab', and very likely the comparison will fail.  "Oops."

To fix this: I had this idea that the "register" storage class might
only be honored if the compiler can find room the all the variables
declared under it:

{
	/* 3 registers left	and ints take one each			*/
	register int a, b, c, d, e;	/* no registers given		*/
}
{
	/* 5 registers left   and doubles use 2 regs (as on a VAX)	*/
	register int x, y;		/* both get registers		*/
	register char *p;		/* gets a register		*/
	register double a, b;		/* 4 reqiered: none given	*/
}

I know this is a painfull and unobvious rule: but is would solve the problem
Doug pointed out.  And any rule that makes register usage safer would be
a help (and with global register allocation one can't predict what will
be put in a register anyway: if only C could do that...).

{							mild flame
	It also bothers me that:
		FILE *fp, *fopen();

	is legal (and common).  I don't like the magic extern at all
	(when "fp" is *not*)!  I believe that a storage class should
	have to apply to all elements of the declaration it acts on.
	This should yeild either
		"auto function %s may not be given at level %d.\n"
	or
		"function %s given auto storage class at line %d\n"
}

And what about allowing an explicit "auto" on formal parameters?
	       ^^^^^^^^
	f(x)
	auto int x;			/* here			*/
	{....}

Or even (gasp) "static"?

Coryphaeus of K,
Kevin Braunsdorf
ksb@j.cc.purdue.edu

gwyn@brl-smoke.UUCP (04/02/87)

In article <3734@j.cc.purdue.edu> ksb@j.cc.purdue.edu.UUCP (Kevin Braunsdorf) writes:
>I know this is a painfull and unobvious rule: but is would solve the problem
>Doug pointed out.

Please note that my specific example was just to illustrate the problem.
Solving just the example and not the general issue seems like a mistake.
Compilers often allocate registers themselves; I was just making this
explicit so people could see the mechanism happening.