Register modifier in C Language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.