Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ucla-cs.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!trwrb!trwrba!cepu!ucla-cs!alex From: alex@ucla-cs.UUCP Newsgroups: net.lang.c Subject: Re: register variables Message-ID: <6115@ucla-cs.ARPA> Date: Mon, 24-Jun-85 13:05:33 EDT Article-I.D.: ucla-cs.6115 Posted: Mon Jun 24 13:05:33 1985 Date-Received: Thu, 27-Jun-85 05:23:52 EDT References: <472@crystal.UUCP> <551@ucsfcgl.UUCP> Reply-To: alex@ucla-cs.UUCP Distribution: net Organization: UCLA Computer Science Department Lines: 40 Summary: >Just be somewhat careful to declare things in the order you care >about. This cuts both ways -- if you move to a machine with fewer >registers than yours, you can loose the most critical register uses in >favor of less critical. For example, let's posit a two register >machine and the following code > > register int i, j; > > for (i = 0; ...) > for (j = 0; ...) > >Now, move it to a one register machine, and "j", which is the most >tested variable, is out of a register and "i", which is used less >often, is still in one. Not what you want. You are assuming the compiler assigns register variables in the order they are declared, which is not always true. An alternative solution is to do something like this: #define REG1 register #define REG2 register ... #define REG8 register /* assume 8 registers on our machine */ #define REG9 ... #define REG20 /* but up to 20 variables that might */ /* be put into registers */ Then declare the local variables as REG1 int j; /* j is most important */ REG2 int i; /* i is next most important */ ... The register #defines can go in a header file that uses #ifdefs to do the #defines appropriately for the machine you are using. This method makes it clear which variables are important to be placed in registers and which aren't. Alex