In c language programs, source files are usually divided into two types: a declaration for saving a program (declaration), a header file, and an implementation (implementation) for saving a program, called a definition file. C Program header file with ". h" as the suffix, c program definition file with ". C" as the suffix.
You can write the contents of the. h file in the. c file, or you can write the contents of the. c file in. h, but that's a bad habit. Many beginners use the first document, but not the reason. Here is a brief explanation.
The header file is used in the following scenario: The library function is invoked through a header file. In many cases, the source code is inconvenient (or not allowed) to the user, as long as the user to provide a header file and binary library can be. The user simply needs to invoke the library functionality according to the interface declaration in the header file, without having to worry about how the interface is implemented. Multi-file compilation. A slightly larger project is implemented into several files, and the function declarations of other files are introduced into the current file through the header file. Header files can enhance type safety checks. If an interface is implemented or used in a way that is inconsistent with the declaration in the header file, the compiler will point out the error, a simple rule that can greatly reduce the burden of debugging and error-changing for programmers.
Only function declarations without function definitions are completely correct at compile time. The function declaration tells the compiler that the function already exists, but the entry address is not yet determined and is temporarily marked here, and the compiler will find the function entry address and replace the tag with the link.
The. obj file that is compiled (Linux is. o files) is already a binary file, similar to the organization of the. exe, except that the entry address of some functions is not found and the program cannot execute. The purpose of a link is to find the function entry address and organize all the source files into a binary file that can be executed.
On the contents of the header file, beginners must also note: The header file can be the same as the C program reference other headers, you can write preprocessing block, but do not write specific statements. You can declare a function, but you cannot define a function. You can declare a constant, but you cannot define a variable. You can "define" a macro function. Note: Macro functions are like functions, but they are not functions. It's actually a statement. The definition of the structure, and the custom data type are generally placed in the header file. #include <filename.h>, the compilation system is referenced in the directory specified by the environment. #include "filename.h", the system is generally first found in the current directory, and then go to the environment to specify directory lookup.
Good style is the key to success, version statement, function description, annotation, etc. are part of the C language program. Do not form a good habit can not become a C language Master (Professional).
In the C standard library, each library function is declared in a header file and can be imported by #include preprocessing command.
The header file is only declared, does not occupy the memory space, compiles the time to be merged to the source file; To know its implementation, to see what the file declared function is defined in which. c file, and then view the source code.
C standard library contains 15 header files, can be divided into 3 groups, how to correctly and skillfully use them, you can be able to distinguish the corresponding 3 levels of programmers: Qualified programmers:<stdio.h>, <ctype.h>, <stdlib.h>, <string.h> Skilled Programmers:<assert.h>, <limits.h>, <stddef.h>, <time.h> excellent programmers:<float.h>, <math.h>, <error.h>, <locale.h>, <setjmp.h>, <signal.h>, <stdarg.h>
The specific contents of each head file please see: C Language Standard library
The C language header file has the following characteristics: idempotent. You can include the same standard header file multiple times, but the effect is the same as only one time. independent of each other. The normal work of any standard header file does not require the inclusion of other standard header files as a prerequisite. Nor does any standard header file contain other standard header files. and file level declarations are equivalent. You must first include a standard header file in your program before you can use what the header file has defined or declared. You cannot include a standard header file in a declaration. Also, you cannot use a macro definition to replace a keyword before it contains a standard header file.
Idempotent is easy to implement, and for most header files you can use macro protection. For example, you might have the following macro definition in stdio.h:
#ifndef _stdio_h #define _STDIO_H/* Main Implementation part */#endif
One of the conventions reached in C programmers is that the beginning of the C source file contains all the header files you want to use. There can be only one comment statement before the #include instruction. The header files introduced can be arranged in any order.
If the header file that we write ourselves might use the definition or declaration in the standard header file, it is best to include the standard header file at the beginning of the custom header file. In this way, you will not forget to introduce the standard header file in your program, and there will be no sequential problems. This is the use of the power of the header file.
Note A convention that introduces a standard header file with angle brackets, introducing a custom header file in double quotes, for example:
#include <stdio.h> #include "myFile.h"
C Language library function is the best practice of header file, carefully read the contents of each header file, especially stdio.h, can learn a lot of things.
found header file in VC6.0C standard header files, such as stdio.h, string.h, etc. are available in the VC6.0 installation directory. My VC6.0 is installed in the C:\Program Files\Microsoft Visual Studio\ directory, then all header files included with VC6.0 (including but not limited to standard header files) are C:\Program Files\Microsoft Visu The Al studio\vc98\include\ directory.
If you forget that the VC6.0 installation directory or header file is not in the installation directory, you can find it in the following ways:
1 Click the "Tools" button in the toolbar
2 Select "Options" in the Level two menu
3 in the Pop-up dialog box, select the "Directory" tab
4 then select Include Files in the Drop-down menu named "Directory", as shown in the following illustration:
Turn from: http://see.xidian.edu.cn/cpp/html/2570.html