Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site harvard.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!stew From: stew@harvard.ARPA (Stew Rubenstein) Newsgroups: net.lang.c Subject: Re: register variables Message-ID: <215@harvard.ARPA> Date: Wed, 26-Jun-85 02:10:38 EDT Article-I.D.: harvard.215 Posted: Wed Jun 26 02:10:38 1985 Date-Received: Fri, 28-Jun-85 00:17:28 EDT References: <472@crystal.UUCP> <551@ucsfcgl.UUCP> Distribution: net Organization: Aiken Computation Laboratory, Harvard Lines: 24 > In article <472@crystal.UUCP> shekita@crystal.UUCP writes: > >1) When is it appropriate to declare a variable as a > > register? I have been told that declaring a variable > > as a register can actually result in slower code. Is > > there a rule of thumb dictating when and when not to > > declare a variable as a register? > > Generally, the only time declaring a variable to be a register > generates slower code is when you declare a parameter to be a > register. This is because, on most systems, this requires a move from > the stack into a register. If the variable is rarely used, this > overhead may cost you more than having it in the register saves. This is not always true. On many (most?) systems, the use of a register in a subroutine requires that the register be saved before use and restored before return. So you get: Move register onto stack If a parameter or initialized auto then move initial value into register Do your subroutine Move saved value back into register On the vax, the register is saved and restored by the CALL instruction, but it still takes time.