How exactly do register variables work in C? When should they be used? K&R touches upon them briefly but moves right along. Is there any source in which I can read about them in depth?
Name:
Anonymous2011-09-25 10:55
when you declare a local variable with the register keyword, you are hinting to the compiler that you would really like it if the compiler allocated the variable within a register, and never have it exist in memory. The compiler wont be able to comply if it doesn't have enough registers available to accommodate the register variable. Also, when you have declared a variable with the register keyword, you can never refer to its location in memory, as it will ideally not even be in memory, just a register. So you can't do this:
register int i;
int* a = &i;
I'm not sure if this is an error or not, but making use of &i will prevent i from being allocated in only a register. But maybe I'm wrong.