In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of what the traceability of C language function is, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article. Let's take a look.
I. the origin of the function
II. Modular programming
III. Modularization in C language
IV. Process-oriented programming
Process-oriented is a process-centered programming idea.
First of all, decompose complex problems into problems that are easy to solve.
The problem after decomposition can be completed step by step.
Function is the embodiment of process-oriented in C language.
Each step of solving the problem can be implemented with a function
V. fame and definition
The meaning of the declaration is to tell the compiler that the program unit exists.
The definition clearly indicates the meaning of the program unit.
Declaration of program units through extern in C language
Some program units can omit extern when declaring
Strictly speaking, the declaration and definition are not the same!
Let's look at an example:
Test.c:
# include # include extern int gourmet var.; / declare extern struct Test; / / declare int main () {extern void f (int I, int j); / / declare extern int g (int x); / / declare struct Test* p = NULL; / / (struct Test*) malloc (sizeof (struct Test)); printf ("p =% p\ n", p); / / g_var = 10 Printf ("g_var =% d\ n", g_var); f (1,2); printf ("g (3) =% d\ n", g (3)); free (p); return 0;}
Global.c:
# include / * the following are definitions * / int g_var = 10; struct Test {int x; int y;}; void f (int I, int j) {printf ("I + j =% d\ n", I + j);} int g (int x) {return (int) (2 * x + g_var);}
The output is as follows:
How do you prove that the declaration is different from the definition? We modify test.c like this, changing struct Test* p = NULL; to struct Test* p = (struct Test*) malloc (sizeof (struct Test))
# include # include extern int gallevar.extern struct Test; int main () {extern void f (int I, int j); extern int g (int x); struct Test* p = (struct Test*) malloc (sizeof (struct Test)); printf ("p =% p\ n", p); / / g_var = 10; printf ("g_var =% d\ n", g_var); f (1,2) Printf ("g (3) =% d\ n", g (3)); free (p); return 0;}
As you can see, the error is reported directly:
Delphi@delphi-vm:~$ gcc test.c global.c
Test.c:6: warning: useless storage class specifier in empty declaration
Test.c: In function 'main':
Test.c:13: error: invalid application of' sizeof' to incomplete type 'struct Test'
This is because the compiler cannot find the definition of struct Test in test.c, only the declaration of struct Test, and therefore cannot know the information about the struct Test structure. The C language compiler does not rely on the compilation order between files when compiling C files.
This is the end of the article on "what is the Origin of C language functions?" Thank you for your reading! I believe you all have a certain understanding of the knowledge of "what is the origin of the C language function?" if you want to learn more knowledge, you are welcome to follow the industry information channel.
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.