HOME

TheInfoList



OR:

In the
C programming language ''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well a ...
, register is a
reserved word In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a re ...
(or keyword), type modifier, storage class, and hint. The register keyword was deprecated in
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, until it became reserved and unused in
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
. It ''suggests'' that the
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
stores a declared variable in a
CPU A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, a ...
register Register or registration may refer to: Arts entertainment, and media Music * Register (music), the relative "height" or range of a note, melody, part, instrument, etc. * ''Register'', a 2017 album by Travis Miller * Registration (organ), th ...
(or some other faster location) instead of in
random-access memory Random-access memory (RAM; ) is a form of computer memory that can be read and changed in any order, typically used to store working data and machine code. A random-access memory device allows data items to be read or written in almost the ...
. If possible depending on the type of
CPU A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, a ...
and complexity of the program code, it will optimize access to that variable and hence improve the execution time of a program. In C (but not C++ where the keyword is essentially ignored) the location of a variable declared with register cannot be accessed, but the sizeof operator can be applied. Aside from this limitation, register is essentially meaningless in modern compilers due to optimization which will place variables in a register if appropriate regardless of whether the hint is given. For programming of embedded systems register may still be significant; for example the Microchip MPLAB XC32 compiler allows the programmer to specify a particular register with the keyword; however, this is discouraged in favor of the compiler's optimizations. When used, register is typically for loop counters, or possibly for other very frequently used variables in the code.


Examples

/* store integer variable "i" in RAM, register, or other location as compiler sees fit */ int i; /* suggests storing integer variable "i" in a CPU register or other fast location */ register int i;


See also

*
Optimizing compiler In computing, an optimizing compiler is a compiler that tries to minimize or maximize some attributes of an executable computer program. Common requirements are to minimize a program's execution time, memory footprint, storage size, and power cons ...
*
Program optimization In computer science, program optimization, code optimization, or software optimization, is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources. In general, a computer program may be o ...
*
Static (keyword) In some programming languages such as C (and its close descendants like C++, Objective-C, and Java), static is a reserved word controlling both lifetime (as a static variable) and visibility (depending on '' linkage''). The effect of the key ...


References

{{Reflist C (programming language) Variable (computer science)