C storage modifier interpretation (pure theoretical part)
In C , the storage space is primarily referred to as a variable or function or class (hereinafter, for convenience of applying the identifier). To this end, C provides the following storage space modifications, which tells the compiler identifier's survival cycle and seeability (which can be understood as a reference), and how these identifiers should be stored.
Survival Space Modifier: AutoregisterStaticextern This article is divided into several parts, each of which is relatively independent.
/ / / Link (Linkage) ///
[Important] Defining how an identifier is referenced
Here I first explain the concept of links. This concept has an important effect on some of the other concepts in this article. The link refers to the identifier that declares in different living spaces or declares that multiple times in the same living space is actually pointing to a common memory space (such as variables or functions). Linkage defines whether an identifier can be referenced in different parts of the program ("also" visible ").
The link in C can be divided into three categories: Internal, External, and No Linkage.
////Iternal linkage ///
If you use Static Space (FileScope) to declare the identifier (variable or function), we say that this identifier is Internal Linkage. Otherwise, let's say this identifier is External Linkage.
//// External Linkage ///
In the file survival space (FileScope), we do not use any storage modifiers to declare the identifier (variable or function), we say that this identifier is ExternalLinkage. Although we should explicitly use the storage modifier extern, the external linkage flag is declared, but because the default case is ExternalInkage, we can provide Extern modifiers without explicit.
///// no linkage ///
If the identifier is declared in a block (Block), without the extern storage modifier modification, we say that this identifier is no linkage, and this identifier is only visible to this block.
// Survival space and visibility //// (Scope and Visibility) ////
[Important] Defining the part of the variable in the program file
I will actually exist first before the following content. The vast universe is so mysterious for us, we can say that things are all in the earth, haha. At least we can think in mind. Because object objective existence is there, do not belong to any individual and group. But do we say that these words make sense? In fact, there is no meaning, just a phenomenon I told. Haha, let's turn this topic again. Although the objects in the vast universe are not part of any individuals and groups, can everyone take it? A simple example you have to go to the moon? no! ! But some people have been there because they have better tools (you can think they have higher privileges). It's so pull, saying that it is here,
The topic is officially started.
The "visibility" of the identifier determines which parts we can can reference in the program. When your code is within the scope of the identifier survival space, you can reference the identifier, otherwise you can't reference the identifier. The living space can be approximately divided into four categories: Function Scope, File Scope, Block Scope, and Function Prototype Scope; explain the relationship between the survival space and identifier visibility:
※ File ScopeFile Scope identifiers are often referred to as "Global" or "External" identifier. The identifier survival period is from the identifier definition or declaration point to the end of the file. ※ Function Scope ※ Block Scope ※ Function-Prototype Scope These three survival spaces are similar, which is not expressed here.
This way I have to use the phenomenon of me, because there is an emergency. The living space is just the necessary conditions for visibility but is definitely not sufficient, and now analyzes the specific problems involved in the File Scope. We are identifiers that the File Scope means that you can quote the identifier anywhere in the program. The prove of practice is not the case, and now you can figure out the reason is our goal. Nice, the identifier in FileScope or the identifier is "global" or "external", which means that these identifier will be placed in the program's data segment (.data segment), but the program Other parts can be quoted to see their own skills. This is related to Linkage. If you haven't figured out the linkage now, look back now. This is the visibility of the identifier. Haha, here you combine the phenomenon that I will talk about before, you can think about it first.
In fact, variables and functions defined in global survival space If they are added to the Static storage identifier, they only define their source files "visible". Other variables and functions defined in global living space are really globally "visible".