c keyword Register, extern, static, some summary

Source: Internet
Author: User

First,Registervariables

keyword regiter requests the compiler to make the variables available to the CPU as much as possible in the register. Here are some points to note.

    1. The register variable must be a type that can be accepted by the CPU register, which usually means that the register variable must be a single value, and its length should be less than or equal to the length of the integral type. However, some machine registers can also store floating-point numbers.
    2. The register variable may not be stored in memory, so the accessor operator "&" cannot be used.
    3. Only local variables and formal parameters can be used as register variables, not global variables.
    4. Static variables cannot be defined as registers.
Second,Static1. Modifier variables (local and global variables)1.1.Static global Variables:

  allocates memory in the global data area; uninitialized static global variable is automatically initialized by the program to 0 (the value of the automatic variable is random, unless it is explicitly initialized) Scope is limited to the file defined by the variable the.

the difference between global variables and global static variables :   

(1 ) Global variables are global variables that are not explicitly decorated with static, but global variables The default is static, the scope is the entire project, the full-board variable defined within one file , and the global variable can be used in another file through the declaration of the extern global variable name .

( 2 ) a global static variable is a global variable that is explicitly decorated with static, the scope is the file in which the other file is used, and the extern declaration is not used.

1.2. Static local Variables2, static functions

Before the return type of the function is prefixed with the static keyword, the function is defined as a static functor . A static function differs from a normal function in that it can only be seen in the file in which it is declared and cannot be used by other files. In other files, you can define a function of the same name , and there will be no conflict.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C keyword Register, extern, static, some summary

Related Article

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.