In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly talks about "how to implement the static modification function in c language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the static modification function in c language.
1. A static function can only be seen in the file in which it is declared, and other files cannot refer to the function.
2. Different files can use static functions with the same name and do not affect each other.
3. Functions declared with static cannot be referenced by another file.
Instance / * file1.c * / # include static void fun (void) {printf ("hello from fun.\ n");} int main (void) {fun (); fun1 (); return 0;} / * file2.c * / # include static void fun1 (void) {printf ("hello from static fun1.\ n");} / * output: error:file1.c: (.text + 0x20): undefined reference to 'fun1' collect2: error: ld returned 1 exit status*/
Expansion of knowledge points:
In C language, the literal meaning of static can easily lead us astray. In fact, it has three functions.
The first and most important item to introduce it: hiding.
When we compile multiple files at the same time, all global variables and functions without the static prefix have global visibility. In order to understand this sentence, I will give an example to illustrate. We need to compile two source files at the same time, one is A.C and the other is main.c.
The following is the content of A.C.
Char a = 'Hello; / / global variablevoid msg () {printf ("Hello\ n");}
The following is the content of main.c
Int main (void) {extern char a; / / extern variable must be declared before use printf ("% c", a); (void) msg (); return 0;}
The running result of the program is:
A Hello
At this point, I believe you have a deeper understanding of "how to implement the static modification function in the c language". 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.