1. Scope
Block scope: With {} wide, ending from declaration start to '} '
function scope: The scope of Goto (identifier) is the entire function.
Function prototype scope: function declaration begins, function declaration ends
File scope: Entire file or program
2. Links
No link: It is visible only within its scope
Inside Link: That is visible from the declaration to the end of the file
External links: Multiple files or the entire program is visible
3. Storage Period
Static storage period: The entire program is occupied with memory
Thread Storage period: thread_local, which is declared after a separate private backup is assigned to each thread
Automatic storage period: Local variables are usually auto-stored
Dynamic storage period: the memory allocated with new or malloc, if not actively released, the entire program occupies memory
4. Summary
Storage class storage Period scope Link Property representation
Automatic automatic block declaration of variables within a non-link block
Register automatic block in non-link block using register decoration
Static external link static file outer link all functions outside
Static inside link static file links all functions outside, with static decoration
Static non-linked static block in a non-link block, using the static modifier
Thread store automatic threads no link thread_local decoration
4. Storage period of function
External functions: Default are external functions
Static functions: Using static modifiers, inner joins
inline function: inline
5. Attention
- Auto indicates automatic storage period in C
- But auto infers the type in c++11
- After the register is declared, it does not necessarily have to be stored in the register, he is just a request. There is no register in time and no address can be taken. There are not many types that can be saved as registers,
Because some types are too large, registers do not exist.
- Static variables, or global constants, are stored in the static zone and are assigned when the program is loaded, and if they are not initialized, they will be initialized to 0, in the BSS segment.
6. Apply for Memory
Malloc:malloc (sizeof (XXX))
Calloc:calloc (num,sizeof (XX))
Realloc:realloc (P,size)
7. Qualifiers
Volatile
Const
Restrict
C language scope, storage period, Link property summary