The sharpening stone of code running in iOS--precompiled instructions
The so-called pre-compilation, is the program code before compiling, the development tool for us to do some of the work beforehand. Don't underestimate the instructions, without them, our code may be a little too difficult.
First, the file contains related preprocessing commands
#include
#include "header"
The C language uses the directive "" and the <> of the include file as the difference between "" is to start looking for files from the current directory,<> is to look for files from the system library. These two instructions do not allow the header file to be introduced in a loop or to contain the same header file repeatedly.
#import "Header"
#import <header>
These two instructions, like the above two functions, are just smarter and intelligently handle the problem of repeating a header file.
#include_next "header"
#include_next <header>
These two instructions are instructions in C, OC is also supported, but rarely used, its role is to find the name matching the header file after skipping, looking for the next same name of the import.
Second, the macro definition
Macro definition is a commonly used in the development of a directive, we will also be many simple functions defined as a macro, eliminating the system stack time, improve code efficiency. Because the topic of this blog is pre-processing commands, the use of macros and advanced usage will no longer be written, the next time to discuss.
#define PARAMETER 1 Parameter 2
define a simple substitution macro without parameters, and in the pre-compilation phase, replace all parameter 1 directly with parameter 2.
#define ADD (x) (x+x)
Defines a macro with parameters, similar to the function of the parameter function, but is also a simple replacement before compiling.
Third, conditional compilation
Conditional compilation is used to determine whether an expression is true or not, and to enter conditional compilation.
Way One:
#if An expression
#else
#endif
Way two:
#if An expression
#elif An expression
#endif
Way three:
#ifndef
If you do not define a macro to compile
#ifdef
If you define a macro to compile
Iv. preprocessing of errors and warnings
#error Error
When the program checks here, it stops compiling, and the command is forbidden to compile in the wrong place.
#warning Warning
This command does not affect the compilation and operation of the program, but will assume that a warning message is displayed here to remind ourselves.
v. Change the file name and line number
In OC, there is a system-defined macro:
__line__
This macro represents the line number of the current row and can be printed.
#line number
Changing the line number of the current row affects all of the following rows
#line number "FileName"
Change the current line number and the compiled file name
Vi. Compiler Control directives
#pragma parameters
This precompiled directive is the most complex, used to control the behavior of the compiler, generally we develop app is rarely used, commonly used in two ways:
#pragma mark-Information
Labeling the Code
#pragma message ("message")
Compile-time prompt information
iOS code run sharpening stone-precompiled instructions