Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: comp.lang.c Subject: Re: Available No. of Registers Message-ID: <4156@utcsri.UUCP> Date: Tue, 17-Feb-87 12:38:50 EST Article-I.D.: utcsri.4156 Posted: Tue Feb 17 12:38:50 1987 Date-Received: Tue, 17-Feb-87 21:12:15 EST References: <3950004@nucsrl.UUCP> <83@ucdavis.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 41 Summary: In article <4141@utcsri.UUCP> flaps@utcsri.UUCP (Alan J Rosenthal) writes: >>order of appearance solves my problem -- I just put the variables in order >>of importance and let the compilers handle it from there. > >Unfortunately, this is not sufficient in the case of register formals. >Consider something like: > > f(n) > register int n; > { register int i; > >where it is considered more useful to put 'i' in a register than 'n'. It >is not possible to arrange the declarations in the appropriate order, and > > f(nformal) > int nformal; > { register int i,n = nformal; > >, which is often recommended, wastes an int on all machines. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ How so? To my understanding, declaring a formal to be register is equivalent to asking for a local register var which is to be initialized to the value of the formal. I.e: foo(x) register int x; { statements.... and foo(xf) { register int x = xf; statements.... are exactly equivalent, provided a register is available. Thus the 'often recommended' solution only wastes an int when the local var (in this case n) cannot be put in a register. Since most C implementations pass parameters on the stack, declaring a formal to be 'register' results in a copy operation from the stack to the register. This copy is implicit in the foo(x) example; the same copy is explicit in the foo(xf) example. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...