Language. Concepts and linkages of C files and. h files

Source: Internet
Author: User

//a.hvoidfoo ();//A.C#include"a.h"  //My question comes out: Is this sentence to be, or not? voidfoo () {return;}//main.c#include"a.h"intMainintargcChar*argv[])  {foo (); return 0;}

Today, it is interesting to see this problem, to record and review some forgotten knowledge points.

Say the answer first, this sentence is necessary!

If A.C is not written, then does the compiler automatically bind the contents of the. h file with the. c file of the same name? A: No.

From the C compiler's point of view,. h and. C are clouds, that is, the renamed. txt,. doc is not a big difference. In other words, the. h and. C Have nothing to do with it. The declarations of variables, arrays, and functions defined in the. c file with the same name are generally placed in H. Declarations that need to be used externally by. C. What's the use of this statement? Just make it easy to quote where these statements are needed. Because #i nclude "xx.h" This macro its actual meaning is to delete the current line, the contents of the xx.h is inserted in the current line position. Because there are so many places to write these function declarations (every call to a function in XX.C is declared all at once), a macro that uses #i nclude "xx.h" simplifies many lines of code-so that the preprocessor can replace itself. In other words, xx.h actually just makes the call where the function declaration in the XX.C needs to be written (fewer lines can be written), as for the include. h file who, is it. h or. c, or the. h with the same name. C, there is no inevitable relationship.
So you might say, "Ah?" I usually just want to call a function in xx.c, but include the Xx.h file, is not a macro replacement after a lot of useless declarations? Yes, it does introduce a lot of rubbish, but it saves you a lot of ink, and the whole layout looks more refreshing. It is this truth that the fish and bear cake cannot be combined.

Language. Concepts and linkages of C files and. h files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.