Register variables


 
Thread Tools Search this Thread
Top Forums Programming Register variables
# 1  
Old 05-23-2002
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
# 2  
Old 05-23-2002
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.
# 3  
Old 10-24-2002
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

https://www.unix.com/programming/6334-register-variables.html?s=

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.
# 4  
Old 10-25-2002
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

I can not register

I want to register as "nezabudka", but I can't and I have a dynamic ip address. My country is not in the list of restrictions. I'm alive, I'm not a bot ))) (3 Replies)
Discussion started by: nezabudka
3 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Not able to register

Hi Admin, Currently, i am not able to register in this site. Kindly let me know what need to done. Thanks, ramesh (1 Reply)
Discussion started by: Unregistered
1 Replies

3. Forum Support Area for Unregistered Users & Account Problems

Cannot able to Register!

Hi Admin, I am unable to register . Request you to help me in getting my registration done. Name: Raghavendra Kulkarni Mail id : <removed> Thanking you in advance for your support. (1 Reply)
Discussion started by: Unregistered
1 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Can't register

I am in China. China is in the blocked country list. I can't register. And I don't have a static ip. Can u help me to fix it. I want to register with following information: Username:liuchengzhang email:<removed> Thanks! (1 Reply)
Discussion started by: liuchengzhang
1 Replies

5. Forum Support Area for Unregistered Users & Account Problems

I can't register

Hello admin, I come from Vietnam, it's in blocked country list. Can you help me to register I want to register with following information: Username: bojankikrick Email: <removed> Thanks very much! (1 Reply)
Discussion started by: Unregistered
1 Replies

6. Forum Support Area for Unregistered Users & Account Problems

Can not register

I need help from the scripting threads and want to register. I tried it several times, but I was all the time rejected, because of your spam policy. I do what you have written, but I wasn't still able to register. (1 Reply)
Discussion started by: ScAr
1 Replies

7. Forum Support Area for Unregistered Users & Account Problems

Cant register

Registration denied. Sorry, The UNIX and Linux Forums runs an active policy of not allowing spammers. Please contact us via by posting in this forum if you believe this is in error What's with this? Tried 2 email accounts in case your forum blocks either. (1 Reply)
Discussion started by: Diagonal
1 Replies

8. Forum Support Area for Unregistered Users & Account Problems

Not able to register

I tried my best to register myself on unix.com but i am not lucky, can you pls give me instruction. (1 Reply)
Discussion started by: Kuldeep_Sngh333
1 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Can't register

I tried registering, but no matter what email address I provide, it says not a valid address and not the same in confirm. I tried many times, but no go. I thought I had already registered as Sully but even that didn't like my email address for password info. Of course, that could be someone else... (2 Replies)
Discussion started by: Not registered
2 Replies
Login or Register to Ask a Question