1, # error
During program compilation, a compilation error occurs when # error occurs. What should I do if it is a compilation error? The purpose is to ensure that the program is compiled as you imagined. The following is an example: a program usually contains many preprocessing commands.
# Ifdef xxx
...
# Else
...
# Endif
When the program is large, some macro definitions are usually specified externally (such as makefile) or in the system header file. When you are not sure whether XXX is defined currently, you can compile it as follows:
# Ifdef xxx
...
# Error "XXX has been defined"
# Else
...
# Endif
In this case, if an error occurs during compilation, XXX has been defined is output, and the macro XXX has been defined. This function can also be used as an error exit warning during compilation.
2, # progma
In a word, # pragma is a macro extension defined to make the C or C ++ program compiled by the compiler fully compatible with machine hardware and operating systems, # pragma is related to a specific compiler.
I. # pragma description (directives)
Each execution of C and C ++ programs supports some unique features of the host or operating system. Some programs, for example, need to precisely control the memory area where data is stored or control the parameters received by a function. # Pragma indicates that the compiler provides a method for compiling on different machines and operating systems to ensure full compatibility between C and C ++. # Pragma is defined by machines and related operating systems and is usually different for each compiler.
Ii. Syntax)
# Pragma token-string (feature string). A feature string is a series of characters that provide instructions and compilation comments to a specific compiler. The symbol (#) must be the first non-space character in the line where Pragma is located; # any space character can be entered between the symbol and Pragma. After # pragma, It is a preprocessing feature character that can be parsed by the compiler. Generally, # pragma is a macro extension. If the compiler finds a pragma that it does not know, it will give a warning but continue compiling. Pragmas can be used in condition declarations to provide the latest functional preprocessing programs, or to provide compiler-defined execution information.