"register" keyword in C?

Nick Van Brunt picture Nick Van Brunt · Feb 23, 2009 · Viewed 116.2k times · Source

What does the register keyword do in C language? I have read that it is used for optimizing but is not clearly defined in any standard. Is it still relevant and if so, when would you use it?

Answer

Brian Knoblauch picture Brian Knoblauch · Feb 23, 2009

It's a hint to the compiler that the variable will be heavily used and that you recommend it be kept in a processor register if possible.

Most modern compilers do that automatically, and are better at picking them than us humans.