During the development process. We often need to define variables or functions that are static types. Let's talk about static in detail next.
1. Modifier variables
When static modifies a variable, it is doomed to the visible range and life cycle of the variable;
(1) When modifying global variables
static int flag1 = 0;
int flag2 = 0;
These two variables are stored in the global data area. Flag1 is only visible in this document. Not visible in other files, Flag2 can be used in other files by declaring extern int flag2;
(2) When modifying local variables
void Fun (void) {
static int temp1;
int temp2 = 0;
......................
Return
}
function. Temp1 is a local static variable, stored in the global data area and TEMP2 as a local variable. Stored on the stack, but as the function exits. The life cycle of the TEMP2 is also over. But Temp1 still works. Only the visible range is within this function. The next time you enter this function again, whatever changes you make to TEMP1 are made on the basis of the last change. That is to say, Temp1 has memory.
2. Modifier function
The function of the static modifier is primarily the function used in this file. Not provided correctly, this type of static function is available in any file in the Linux kernel.
static inline void Enable_noirq (void) {
................
}
The advantage of using the static modifier function is. All files can define a function with the same name, without considering the compilation error caused by the duplicate names;
Use of static in C language