The process of compiling the program can be divided into three parts: preprocessing, compiling and assembling, in which preprocessing is the first process, the preprocessing process is the source code, the initial conversion is made, and the new source code is provided to the compiler.
After the preprocessing is read into the source code, the preprocessing instructions contained in the code are checked to complete tasks such as containing additional source files, defining macros, and depending on the conditions to determine if the compilation contains some code.
By precompiling the instructions, only the code that satisfies the condition is compiled, and the other code does not participate in the compilation
1, instruction
Precompiled directives are #开头, and the entire statement forms a precompiled directive
2, function
There are three main aspects in the preprocessing of C + + language: 1. macro definition; 2. file contains; 3. Conditional compilation.
3, some common precompiled directives
#include
#define #undef
#define指令定义了一个标识符及一个串, identifiers are called macro names, and each occurrence of a macro name in the source program is replaced with its defined string, called a macro substitution.
#undef指令取消一个已定义的宏
#if #elif #else #endif (detailed)
Cross-platform often uses code, which can be written inside or outside the function
#if defined (WP8) ... #elif defined (ANDROID) ... #elif defined (IOS) ... #endif
So depending on the platform, the compiler will choose different code to compile, throw away the code of the other platform.
So WP8 ANDROID IOS How are these predefined macros defined?
The predefined macro method under XCode (only need to add iOS macros here, so that compiling runs or packaging will only compile the code below iOS )
http://blog.csdn.net/tutuboke/article/details/44855777
How Eclipse ANDROID Pre-defined macros (this compiles conditional compilation directives #elif defined (ANDROID) code, compiled *.so files will not contain code from other platforms)
Need to add Android Mk file in *.mk file to compile so file
Local_cflags +=-dandroid is equivalent to getting #define ANDROID in C + +
VS WP8 Set the precompiled instruction method: (This will only compile the conditional compilation directive WP8 the following code)
->c/c++, Preprocessor--
#ifdef #ifndef #endif
#ifndef myhead_h#define myhead_h#include "MyHead.h" #endif
The role of precompiled directives across platforms