C language .h and .c file parsing

c language .c and .h file:

  There is no difference in essence. But in general: .h header file is a file that contains function declarations, macros, and other content structure is defined

  .c file is a program file that contains functions to achieve, variable definitions and other content . And what suffix does not matter, but the compiler will default to take certain actions on certain file suffix. You can force the compiler to any extension of the file as c files to compile.

  Such written in two separate files is a good programming style.

  Also, say I define a function aaa.h in a statement, and then I build aaa.c in the same directory aaa.h of aaa.c defined in the implementation of this function, and is located in the main function #include .c file this aaa.h then I can use this function a. main will find this function defines aaa.c file at run time.

  This is because:

  The main function is the standard C / C ++ program entry, the compiler tries to find the file where the function .

  Assumed compiler compiling myproj.c (which contains main ()), we found that it include the mylib.h (which declares a function void test ()), then the time compiler (Include path list according to the path set in advance and where the code file path) to find the same name in the implementation file (extension .cpp or .c, in this example mylib.c), if the file is found, and where to find the function (in this case, void test ()) implementation code, the compiler will continue; if achieved can not find the file in the specified directory, or the file and follow each include file is not found in the implementation code, a compiler error is returned in fact, the process can include. "as" a document splicing process, the declarations and implementations are written in the C header files and documents, or both simultaneously written in the header file, in theory there is no essential difference .

 

  These are the so-called dynamic way.

 

 

 

 

 

 

 

 

Because #include "xx.h" This macro its actual meaning is to delete the line current, the content of intact xx.h inserted in the current line.

Due to these places want to write a function declaration is very large (in every place call xx.c function, should be in use before the declaration of a sudden),

Therefore, the use #include "xx.h" This macro simplifies many lines of code - let preprocessor to replace its own good. In other words, xx.h fact, just let xx.c need to write a function declared local calls (you can write a few lines less),

As for who include the .h file yes, yes .h or .c, or .h .c with the same name, they are not necessarily any relationship.

 

Guess you like

Origin www.cnblogs.com/focusonoutput/p/12329510.html