First, the origin of pretreatment: There are many language characteristics (especially the obscure language of the language) in the history of C , and the pre-treatment is one of them. C inherits the C language pre-processor from the C language (C language pre-processor, by Dr. Bjarne is referred to as CPP, I don't know if it is referred to as C Program Preprocessor).
Second, the common pretreatment function: The main role of the preprocessor is to replace a resource through the preprocessing built-in function. The most common preprocessor is: file containing, conditional compilation, layout control and macro replacement . The file contains: #include is a most common preprocessing, mainly to be a reference combination source program body. Conditional compilation: # if, # iFNDef, # ifdef, # Endif, # undef, etc. is also a common pre-process, mainly for compile time with selective selection, comment down some specified code to achieve version control, preventive The file repeatedly included. Layout control: #Progma, which is an important aspect of our application pretreatment, the main function is to provide unconventional control flow information for compilers. Macro replacement: #define, this is the most common usage, it can define various functions such as symbol constants, function functions, renamed, string splicing. Third, pre-processing instructions: The format of the pre-processed instruction is as follows: # Directive tokens # symbols should be the first non-empty character of this line, usually we put it in the starting position. If the instruction can't put it, it can be controlled by / control, for example: #define error if (error) exit (1) equivalent to #define error / if (error) exit (1) but we are generally not very so used, the more common as follows: # ifdef __BORLANDC__ if_true <(is_convertible :: value)> :: template then :: type Make; # else enum {is_named = is_named_parameter :: Value}; type}; type <(is_named)> :: template the ":: TYPE_KEY_VALUE> :: Type Make; # Endif Let's take a look at the common pretreatment instruction: #define macro definition #undef unfained macro #include Text contains #ifdef If the macro is defined to compile #ifndef If the macro is not defined, the control #IF expression of the compiling #Endif ends the compiling block is compiled. #ELSE is compiled as other pre-processed residual options. #ELIF This is a combination of #LSE and #IF #LINE Change the current number of rows and file name #Error outputs an error message #pragma provides unconventional control flow information for compileries. We will take these pre-processes. One note, considering the importance and cumbersome of the macro, we put it in the end.
Fourth, the file contains instructions: This pre-processing method is the most common, usually we write programs, the most common usage is: #include file: // Standard library header file #include File: // Old-style standard library header file #include "io.h" file: // user-defined header file #include "../file.h" file: // unix under the parent directory File #include "/usr/local/file.h" File: // Unix under the full path #include "../file.h" File: // DOS under the parent directory under the parent directory under the parent directory "/ usr /LOCAL/FILE.H "File: // DOS's full path to this inside This should pay attention: 1, we use or ? We advocate , not , why? I think you may remember that I have given a few reasons, here I roughly say: First, .h format header file is abandoned by the Standard Commission in September, in September, in September, and we should follow the standard, Suitable for the development of the times. Second, iostream.h only supports narrow character sets, iostream supports narrow / wide character sets. Also, standards have made many changes in iostream, and interfaces and implementations have changed. Finally, iostream components are all put in Namespace STD to prevent name pollution. 2, and "IO.H" difference? In fact, their only difference is that the search path is different: for the #include , the compiler starts searching from the standard library path to the #include "io.h", the compiler starts searching from the user's work path