Preprocessing: English
# Error
# The error command is one of the pre-processing commands in the C/C ++ language. When the pre-processor pre-processes to the # error command, it stops compiling and outputs custom error messages.
# Define SIZE 3int main () {# if SIZE> 4 & SIZE <36 # error "++" # endif} // The debug succeeds because the condition is not met.
# Line Processing
1 #include "stdio.h" 2 void Test(); 3 #line 10 "Hello.c" 4 int main(int argc, char* argv[]) 5 { 6 #define CONST_NAME1 "CONST_NAME1" 7 printf("%s/n",CONST_NAME1); 8 #undef CONST_NAME1 9 printf("%s/n",CONST_NAME1);10 {11 #define CONST_NAME2 "CONST_NAME2"12 printf("%s/n",CONST_NAME2);13 }14 printf("%s/n",CONST_NAME2);15 return 0;16 }17 void Test()18 {19 printf("%s/n",CONST_NAME2);20 }
The following compilation information is prompted:
Hello. c (15): error C2065: 'const _ name1': undeclared identifier
Indicates that the name of the current file is considered as Hello. c, # line 10 "Hello. c" is in the next row and is considered as 10th rows. Therefore, an error occurs in row 15th.
# Pragma preprocessing
# Pragma once
This header file is usually used to start the header file. During pre-compilation, this header file is inserted only once.
For example, the header file "grandfather. h"
1 # pragma once2 # ifndef GRANDFATHER_H3 # define GRANDFATHER_H4 struct foo5 {6 int member; 7}; 8 # endif/* GRANDFATHER_H */View Code
When this program is included multiple times (when multiple files are compiled and each other is included), it is only inserted and compiled once.
# Pragma once Compilation speed is faster than # ifndef GRANDFATHER_H # define GRANDFATHER_H,
Therefore, it is often used in all cases.
The difference with # ifndef # define is visible: http://www.cppblog.com/cxiaojia/archive/2013/03/18/198526.html
# Pragma comment
# Pragma comment (...)
This command puts a comment record into an object file or executable file.
It is often used to link a dynamic library, such
# Pragma comment (lib, "user32.lib ");
There are also linker: put a link option into the target file. You can use this command to forcibly include an object instead of the link options passed in by the command line or set in the development environment, for example:
# Pragma comment (linker, "/include: _ mySymbol ")
# Pragma code_seg
1 void func1 () {// stored in the code segment by default. 2} 3 4 # pragma code_seg (". my_data1 ") 5 6 void func2 () {// stored in the code segment. in my_data1, 7} 8 9 # pragma code_seg (push, r1 ,". my_data2 ") 10 11 void func3 () {// stored in the code segment. in my_data2, 12} 13 14 # pragma code_seg (pop, r1) 15 16 void func4 () {// stored in the code segment. 17 In my_data1}
It can set the code segment where function code is stored in the program. It is used when we develop the driver.
# Pragma hdrstop
# Pragma hdrstop indicates that the header file is pre-compiled till now, and the header file is not pre-compiled. BCB can pre-compile the header file to speed up the link, but if all header files are pre-compiled, it may occupy too much disk space. Therefore, this option is used to exclude some header files.
# Pragma warning
# Pragma warning (disable: 4507 34; once: 4385; error: 164)
It is equivalent:
# Pragma warning (disable: 4507 34) // do not display the 4507 and 34 Warnings
# Pragma warning (once: 4385) // only one warning message is reported once
# Pragma warning (error: 164) // the error message 164 is used as an error.
This pragma warning also supports the following formats:
# Pragma warning (push [, n])
# Pragma warning (pop)
Here n represents a warning level (1---4 ).
# Pragma warning (push) saves the existing warning status of all warning information.
# Pragma warning (push, n) saves the existing warning status of all warning information, and sets global warning
The level is set to n.
# Pragma warning (pop) pops up the last warning message to the stack.
All changes are canceled. For example:
# Pragma warning (push)
# Pragma warning (disable: 4705)
# Pragma warning (disable: 4706)
# Pragma warning (disable: 4707)
//.......
# Pragma warning (pop)
At the end of the Code, save all warning information (including 4705,470 6 and 4707 ).