I'm reading through K&R and came to the small section on register variables, and was wondering if people here have some good examples of this put into practice.
From section 4.7 in K&R:
The register declaration looks like
register int x;
register char c;
To be clear, I'm just hoping to see some cool code samples. I (am pretty sure that I) understand the subject matter so don't feel the need to type up a verbose explanation (unless you want to).
There is no good example of register usage when using modern compilers (read: last 15+ years) because it almost never does any good and can do some bad. When you use register, you are telling the compiler "I know how to optimize my code better than you do" which is almost never the case. One of three things can happen when you use register:
Even if one compiler produces better code when you use register, there is no reason to believe another will do the same. If you have some critical code that the compiler is not optimizing well enough your best bet is probably to use assembler for that part anyway but of course do the appropriate profiling to verify the generated code is really a problem first.