The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Novell won't pull a SCO - Register iBot UNIX and Linux RSS News 0 08-16-2007 02:20 PM
Register RSA Key fingerprint with JVM 1.4.2 asawari UNIX for Dummies Questions & Answers 0 06-14-2006 03:04 AM
Can't register Not registered Forum Support Area for Unregistered Users & Account Problems 2 01-27-2006 12:46 PM
vi: deleted text not placed in register maxporter UNIX for Dummies Questions & Answers 3 01-26-2006 10:34 PM
register unsuccessfully Javier Forum Support Area for Unregistered Users & Account Problems 1 02-18-2005 03:04 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2002
Registered User
 

Join Date: Mar 2002
Location: Greece
Posts: 14
Register variables

Hi
Is there any limit on the number of register variables can be used at any one time?
Does this limit depends on the number registers that the CPU holds?

In a large program is it wise to declare all the loop counter as register variables?

Thanx
Andonis Matsakas
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,663
The register keyword is just a hint to the compiler. There is no limit on how many times you can use that hint. There is also no guarantee that any of the variables will wind up with a somewhat dedicated register.

The register keyword is largely obsolete and I would not recommend using it for new code. Today's optimizers are very good at allocating registers where they are do the most good. And, by the way, today's risc and post-risc cpu's tend to have lots of registers to allocate. Registers aren't the scarce resource that they were in the 70's.
Reply With Quote
  #3  
Old 10-24-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
When to use register variables?

Hi,

I never clearly understood when to use the keyword "register", I just know that it is a request to the system to provide space for this object in the CPU registers, which are faster in accessing than RAM.

Can anyone provide me a small practical situation where it becomes imperative to use the keyword "register"?

I would also appreciate if someone suggests me a good book which emphasizes the use of registers.

I have searched the forums and found this thread

Register variables

but it didn't answer my question - in which situations do we use them? I have seen industry strength C programs written by experts, which chose certain variables to be registers while declaring others as normal types, but couldn't quite appreciate why certain variable need to be a register.

Thank you!
Vishnu.
Reply With Quote
  #4  
Old 10-25-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,663
No one can give you an example where it is imperative to use the register keyword. It is never imperative. It never was. It never will be.

An example of where is might be useful is something like:

Code:
register int i;
register int tot;
int table[1000];
tot=0;
for(i=0; i<1000; i++)
    tot += table[i];
The idea is that if i stays in a register we can save some time. We don't want to store i back in memory after it gets incremented in the "for" statement and then read it back to use in the next statement. Same deal with tot. We don't want to store it in memory each iteration just to read it back so that we can add to it again.

But to make the above code actually useful, you must compile it with a very old compiler. Modern compilers will figure this out by themselves.

And you really need to be an assembler programmer to fully grasp this. You need to understand what a register is. And that machine language instructions move data between registers and memory. So the books to read are those on assembly language programming. Mastering assembler should clear this right up.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0