Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site ucsfcgl.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ucbvax!ucsfcgl!arnold
From: arnold@ucsfcgl.UUCP (Ken Arnold%CGL)
Newsgroups: net.lang.c
Subject: Re: register variables
Message-ID: <558@ucsfcgl.UUCP>
Date: Wed, 26-Jun-85 17:35:29 EDT
Article-I.D.: ucsfcgl.558
Posted: Wed Jun 26 17:35:29 1985
Date-Received: Fri, 28-Jun-85 00:43:38 EDT
References: <472@crystal.UUCP> <551@ucsfcgl.UUCP> <6115@ucla-cs.ARPA>
Reply-To: arnold@ucsfcgl.UUCP (Ken Arnold)
Distribution: net
Organization: UCSF Computer Graphics Lab
Lines: 34

In article <6115@ucla-cs.ARPA> alex@ucla-cs.UUCP writes:
>>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.

It SHOULD always be true.  If a compiler doesn't put things in
registers in the order declared, it is not following (a) standard
practice, or (b) K&R (the closest thing we currently have to a
standard).  K&R says

	A "register" declaration is best thought of as an "auto"
	declration, together with a hint to the compiler that the
	varibles declared will be heavily used.  Only the first few
	such declarations are effective.

"first few" means "first few".  In the above listing, "i" comes before
"j" and therefore is part of the "first few" before "j" is.  Any compiler
which puts "j" in first is doing it wrong.

		Ken Arnold