Jump to content

C++ Programming

From Wikibooks, open books for an open world

The register keyword is a request to the compiler that the specified variable is to be stored in a register of the processor instead of memory as a way to gain speed, mostly because it will be heavily used. The compiler may ignore the request.

The keyword fell out of common use when compilers became better at most code optimizations than humans. Any valid program that uses the keyword will be semantically identical to one without it, unless they appear in a stringized macro (or similar context), where it can be useful to ensure that improper usage of the macro will cause a compile-time error. This keywords relates closely to auto.

register int x=99;

Note:
Register has different semantics between C and C++. In C it is possible to forbid the array-to-pointer conversion by making an array register declaration: register int a[1];.