#pragma pretreatment instruction details
In all preprocessing instructions, the # prgMA instruction may be the most complicated, its role is to set the status of the compiler or indicate that the compiler does some specific actions. #pragma instructions give each compiler a method to give the host or operating system proprietary feature in the case where the C and C language is fully compatible. Based on definitions, compilation indication is perfect for machines or operating systems and is different for each compiler.
Its format is generally: #pragma para. Where parameters are parameters, look at some common parameters.
(1) Message parameters. The Message parameter is my favorite parameter, which can output the corresponding information in the Compilation Information Output window, which is very important for the control of source code information. The method of use is: #pragma Message ("Message Text"), when the compiler encounters this instruction, print the message text in the compilation output window.
When we define many macros in the program to control the source code version, we may have forgotten that there is no correct settings. At this time we can use this instruction to check when compiling. Suppose we want to determine if you have anywhere in the source code _X86 this macro can be used in the following method
#ifdef _x86
#Pragma message ("_ x86 macro actid!")
#ENDIF
When we define the _x86 macro, the application will display "_ x86 macro actid!" In the compilation output window when compiling. We will not scratch it because of some specific macro they define.
(2) Another multi-use PRAGMA parameter is Code_SEG. Formats such as:
#pragma code_seg ([Section-Name "[," Section-Class "]])
It can set the code segment stored in the program in the program, which will be used when we develop the driver.
(3) #pragma ONCE (more common)
As long as the first instructions in the header file can guarantee that the header file is compiled once, this instruction is actually in VC6, but considers compatibility and not much using it.
(4) #pragma HDRSTOP indicates that the pre-translated header files will be, and the header files will not be precompiled. The BCB can pre-translate the header file to speed up the speed of the link, but if all header files are pre-compiled, it may account for too much disk space, so use this option to exclude some header files.
There is a dependency between the units, such as unit A dependent unit B, so unit B is compiled by unit A. You can use #pragma startup to specify compilation priority, if #pragma package (smart_init) is used, BCB will compile according to the size of the priority.
(5) #pragma resource "* .dfm" means adding resources in the * .dfm file to the project. * .dfm includes the definition of the form of the form.
(6) #pragma Warning (Disable: 4507 34; Once: 4385; Error: 164)
Equivalent to:
#pragma Warning (Disable: 4507 34) // Does not display 4507 and 34 warning information
#pragma Warning (ONCE: 4385) // 4385 Warning information only reports once
#pragma Warning (Error: 164) // Put the 164 warning message as an error.
At the same time, this Pragma Warning also supports the following format:
#pragma Warning (push [, n])
#pragma Warning (POP)
Here n represents a warning level (1 --- 4). #pragma Warning (Push) Save existing warning status of all warning information.
#pragma warning (push, n) Save existing warning status of all warning information, and set the global warning level to n.
#pragma Warning (POP) pops up the last warning message in the stack, canceling all changes made between the stack and out of the stack.
E.g:
#pragma Warning (Push)
#pragma Warning (Disable: 4705)
#pragma Warning (Disable: 4706)
#pragma Warning (Disable: 4707)
// .......
#pragma Warning (POP)
At the end of this code, re-save all warning information (including 4705, 4706, and 4707).
(7) Pragma Comment (...)
This instruction puts a comment record into an object file or executable.
Commonly used lib keywords can help us connect into a library file.
Each compiler can activate or terminate some of the compiler supported by the #pragma instruction. For example, a loop optimization function:
#pragma loop_opt (on) // activation
#pragma loop_opt (OFF) // termination
Sometimes some functions in the program make the compiler issues a warning you are familiar with, such as "Parameter XXX Is Never Used In Function XXX", you can:
#pragma warn -100 // Turn Off The Warning Message for Warning # 100
INT INSERT_RECORD (REC * R)
{/ * Function body * /}
#pragma warn 100 // Turn The Warning Message for Warning # 100 Back on
The function generates a warning message with a unique signature 100, so that the warning is temporarily terminated.
Each compiler is different from #pragma, which is valid in a compiler to be almost invalid in another compiler. You can view from the compiler's documentation.