Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!oberon!cit-vax!glewis
From: glewis@cit-vax.Caltech.Edu (Glenn M. Lewis)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Lattice 4.1 register yuck!
Message-ID: <7029@cit-vax.Caltech.Edu>
Date: 22 Jun 88 17:30:41 GMT
References: <8806212123.AA01328@cory.Berkeley.EDU>
Reply-To: glewis@cit-vax.UUCP (Glenn M. Lewis)
Organization: California Institute of Technology
Lines: 50

In article <8806212123.AA01328@cory.Berkeley.EDU> Matt Dillon writes:
>...
>	One thing I have yet to see addressed properly by either Aztec or
>Lattice is the following:
>
>	{
>	    register short i, j, k;
>
>	    for (i = 0; i < 10; ++i)
>		
>	    for (j = 0; j < 10; ++j) 
>		
>	    for (k = 0; k < 10; ++k)
>		
>	}
>
>	I is not used while J is being used, neither I or J are being
>	used while K is being used, etc....
>
>	ONLY ONE REGISTER SHOULD BE USED FOR ALL THREE REGISTER VARIABLES!!

	Are you suggesting that the compiler ought to figure out that the
value of 'i' will not be used again in this function, and the same for 'j'
and 'k'?  It seems that you are.  That would be interesting.

	Often, when manipulating strings, I have a register variable such
as 'i' the runs through the string in a for loop, and then I use the value
after it, and then continue in another for loop.  But I don't believe that
I have ever written a routine that declared more than one register variable
where that variable couldn't be re-used, if the value was no longer needed.
In other words, if I had a situation like the one above, I would just say
	"register int i"
and just let 'i' handle all those loops.  I don't see any need to allocate
two more variable to do the work that the first one could have done.

	I believe it would be dangerous to let the compiler re-use a variable
in the manner that you describe, especially when using a debugger.  If you
check the address and/or value of 'i' or 'j', they would be the same, and
you would think that a bug has been found.

	But yes, I agree that if the compiler were smart enough to look
through the entire routine before allowing re-use of a register variable,
that it should work properly.  I would just like to point out that it is
easy enough for the programmer to detect these situations, and use the
register variable over "manually".

							-- Glenn

-- 
glewis@cit-vax.caltech.edu