Register Variables

Data in the machine-language version of a program is normally loaded into registers for calculations and other processing.

The compiler might ignore register declarations. For example, there might not be a sufficient number of registers available. The following definition suggests that the unsigned int variable counter be placed in one of the computer’s registers; regardless of whether the compiler does this, counter is initialized to 1:

register unsigned int counter = 1;

The register keyword can be used only with local variables and function parameters.

Image Performance Tip 6.2

The storage-class specifier register can be placed ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.