In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the keywords in the c language storage class". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the keywords in the c language storage class.
-auto-
(1) the auto keyword has only one function in C language, that is, to modify local variables.
(2) auto modifies the local variable, indicating that the local variable is an automatic local variable, and the automatic local variable is assigned on the stack. (since
On the stack, it means that the value is random if it is not initialized.
(3) the definition of local variables is usually the definition of auto, but omitted the auto keyword. It can be seen that the local variable of auto is actually the ordinary local variable defined by default.
-static-
(1) there are two uses of the static keyword in C language, and the two uses are completely independent of each other. In fact, one more keyword should have been invented at that time, but the authors of the C language thought that too many keywords were bad, so they added a usage to static, which led to the fact that a keyword static had two completely different meanings.
(2) the first use of static is to modify local variables to form static local variables. Make clear the difference between static local variables and non-static local variables. The essential difference is that the storage classes are different (different storage classes give rise to many differences): non-static local variables are assigned on the stack, while static local variables are assigned on the data segment / bss segment, in the data segment, it is initialized, in the bss segment, we generally do not initialize, the default is generally 0, which is the same as the global variable is not initialized.
# include
Int main (void)
{
Static a
Printf ("the an is% d\ n", a)
Return 0
}
The result of the demonstration:
The an is 0
(3) the second use of static is to modify global variables to form static global variables. Make clear the difference between static global variables and non-static global variables. The difference is in the link properties, as described below. Let me give you a few examples here:
-not modified with the static keyword:
# include
Void test ()
{
Int num = 0
Num++
Printf ("d", num)
}
Int main ()
{
Int I = 0
For (I = 0; I < 10; iTunes +)
{
Test ()
}
Return 0
}
The result of the demonstration:
1 1 1
-modified with static:
# include
Void test ()
{
Static int num = 0
Num++
Printf ("d", num)
}
Int main ()
{
Int I = 0
For (I = 0; I < 10; iTunes +)
{
Test ()
}
Return 0
}
The result of the demonstration:
1 2 3 4 5 6 7 8 9 10
(4) Summary:
Static local variables are the same as global variables in storing classes.
Static local variables are the same as global variables in terms of life cycle.
The differences between static local variables and global variables are: scope, connection properties. The static local variable scope is the code block scope (the same as the ordinary local variable), the link attribute is connectionless; the global variable scope is the file scope (the same as the function), and the link attribute is outer join. Let's start with a brief description of three link properties:
(1) external links mean external link attributes, that is, external links can be linked within the entire program scope (meaning across files), for example, ordinary functions and global variables belong to external links.
(2) Inner link means (internal c file) internal link attribute, that is, this guy can link within the internal scope of the current c file (meaning that it cannot be accessed and linked in other c files outside the current c file). Static-decorated functions / global variables belong to inner links.
(3) No connection means that the symbol itself does not participate in the link, it has nothing to do with the link. All local variables (auto, static) are connectionless.
(5) static functions (modified with this static keyword) must have come into contact with readers of stm32 (here, I will not give an example) When you have a lot of source files in your program (which is often encountered when writing stm32, and you often have to get into the habit of writing code that multiple files are not repeatedly included), you usually use this static keyword in stm32 to modify the function, so this function can only be used in this file, not externally (the scope of this function can only be in the current file) In fact, it is similar to the difference between global variables and static global variables mentioned above.
-register-
(1) the register keyword is not commonly used and has only one function, that is, the variable modified by register. The compiler will try to allocate it in the register. (usually allocated variables are in memory, in fact, the process of reading data in memory is like this: cpu+ register + cache+ memory). The allocation is the same in registers, but it is much more efficient to read and write. So the variable modified by register is used when the variable is used repeatedly and frequently, and the efficiency of the program can be greatly improved by improving the access efficiency of this variable. Therefore, register is a means to improve the efficiency of the program.
(2) when writing code, it is rare to be defined as register, so it is generally used with caution.
(3) the register compiler can only promise to put register-decorated variables in registers as much as possible, but not necessarily in registers. The main reason is that the number of registers is limited and may not be available.
At this point, I believe you have a deeper understanding of "what are the keywords in the c language storage class?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.