Register modifier implies CompilationProgramThe corresponding variables will be frequently used. If possible, they should be stored in CPU To speed up its storage. For example, the following memory block copyCode,
# Ifdef nostructassign
Memcpy (D, S, L)
{Register char * D;
Register char * s;
Register int I;
While (I --)
* D ++ = * s ++;
}
# Endif
However, the Register modifier has several restrictions.
First, the register variable must be a type that can be accepted by the CPU. This usually means that the register variable must be a single value and the length should be less than or equal to the length of an integer. However, some machine registers can also be stored. Floating Point Number .
Second, because the register variable may not be stored in the memory, you cannot use "&" to obtain the address of the register variable.
Due to the limited number of registers, and some registers can only accept specific types of data (such as pointers and floating-point numbers ), therefore, the real number and type of the register modifier depend on the machine where the program runs, and any redundant register modifier will be ignored by the compiled program.
In some cases, saving variables in registers reduces the running speed of the program. Because the occupied registers cannot be used for other purposes; or the number of times variables are used is not enough, it is not enough to load and store the additional overhead of variables.
Early C compilation programs do not store variables in registers unless you command them to do so. At this time, the register modifier is a valuable supplement to the C language. However, with the development of Compilation Program design technology, the current C compiling environment can make better decisions when deciding that variables should be stored in registers. In fact, many compilers ignore the register modifier, because although it is completely legal, it only implies rather than command.