Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ptsfa!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!ksb From: ksb@j.cc.purdue.edu.UUCP Newsgroups: comp.lang.c Subject: Re: ANSI Oct 86 Public draft (register honored). Message-ID: <3734@j.cc.purdue.edu> Date: Wed, 1-Apr-87 10:43:29 EST Article-I.D.: j.3734 Posted: Wed Apr 1 10:43:29 1987 Date-Received: Sat, 4-Apr-87 08:39:17 EST References: <4804@brl-adm.ARPA> <365@bms-at.UUCP> Reply-To: ksb@j.cc.purdue.edu.UUCP (Kevin Braunsdorf) Distribution: na Organization: Solon Aquilla's Magic & Art Shoppe Lines: 73 In article <5708@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) 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 > > 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